dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19774
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8763: Impl recovery user interface
------------------------------------------------------------
revno: 8763
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-30 09:50:49 +0300
message:
Impl recovery user interface
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/restore.js
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message1.vm
dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message2.vm
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/security/SecurityServiceTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/account.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/recovery.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2012-10-29 19:27:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2012-10-30 06:50:49 +0000
@@ -37,6 +37,7 @@
import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.message.MessageSender;
import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.system.velocity.VelocityManager;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserCredentials;
@@ -50,6 +51,9 @@
{
private static final String RESTORE_PATH = "/dhis-web-commons/security/restore.action";
+ private static final int TOKEN_LENGTH = 50;
+ private static final int CODE_LENGTH = 15;
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -88,7 +92,12 @@
UserCredentials credentials = userService.getUserCredentialsByUsername( username );
- if ( credentials == null )
+ if ( credentials == null || credentials.getUser() == null || credentials.getUser().getEmail() == null )
+ {
+ return false;
+ }
+
+ if ( !ValidationUtils.emailIsValid( credentials.getUser().getEmail() ) )
{
return false;
}
@@ -120,8 +129,8 @@
public String[] initRestore( UserCredentials credentials )
{
- String token = CodeGenerator.generateCode( 40 );
- String code = CodeGenerator.generateCode( 15 );
+ String token = CodeGenerator.generateCode( TOKEN_LENGTH );
+ String code = CodeGenerator.generateCode( CODE_LENGTH );
String hashedToken = passwordManager.encodePassword( credentials.getUsername(), token );
String hashedCode = passwordManager.encodePassword( credentials.getUsername(), code );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message1.vm'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message1.vm 2012-10-29 20:17:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message1.vm 2012-10-30 06:50:49 +0000
@@ -8,4 +8,5 @@
You must complete the restore process within 1 hour. If you take no action, your
-account will not be restored.
+account will not be restored. If you did not request this restore, please disregard
+this message.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message2.vm'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message2.vm 2012-10-29 20:17:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/restore_message2.vm 2012-10-30 06:50:49 +0000
@@ -8,4 +8,5 @@
You must complete the restore process within 1 hour. If you take no action, your
-account will not be restored.
\ No newline at end of file
+account will not be restored. If you did not request this restore, please disregard
+this message.
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/security/SecurityServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/security/SecurityServiceTest.java 2012-10-29 14:34:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/security/SecurityServiceTest.java 2012-10-30 06:50:49 +0000
@@ -61,6 +61,7 @@
credentials.setPassword( "" );
User user = createUser( 'A' );
+ user.setEmail( "valid@xxxxxxxxx" );
user.setUserCredentials( credentials );
credentials.setUser( user );
userService.addUserCredentials( credentials );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-10-29 19:27:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-10-30 06:50:49 +0000
@@ -114,7 +114,7 @@
log.info( "Recovery message sent for user: " + username );
- response.setStatus( HttpServletResponse.SC_CREATED );
+ response.setStatus( HttpServletResponse.SC_OK );
return "Recovery message sent";
}
@@ -149,7 +149,7 @@
log.info( "Account restored for user: " + username );
- response.setStatus( HttpServletResponse.SC_CREATED );
+ response.setStatus( HttpServletResponse.SC_OK );
return "Account restored";
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/account.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/account.js 2012-10-23 15:01:19 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/account.js 2012-10-30 06:50:49 +0000
@@ -75,4 +75,4 @@
function reloadRecaptcha()
{
Recaptcha.reload();
-}
\ No newline at end of file
+}
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/restore.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/restore.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/restore.js 2012-10-30 06:50:49 +0000
@@ -0,0 +1,26 @@
+
+function recoverAccount()
+{
+ var username = $.trim( $( "#username" ).val() );
+
+ if ( username.length == 0 )
+ {
+ return false;
+ }
+
+ $.ajax( {
+ url: "../../api/account/recovery",
+ data: {
+ username: username
+ },
+ type: "post",
+ success: function( data ) {
+ $( "#recoveryForm" ).hide();
+ $( "#recoverySuccessMessage" ).fadeIn();
+ },
+ error: function( data ) {
+ $( "#recoveryForm" ).hide();
+ $( "#recoveryErrorMessage" ).fadeIn();
+ }
+ } );
+}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/recovery.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/recovery.vm 2012-10-29 20:17:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/recovery.vm 2012-10-30 06:50:49 +0000
@@ -3,10 +3,7 @@
<head>
<title>DHIS 2</title>
<script type="text/javascript" src="../javascripts/jQuery/jquery.min.js"></script>
- <script type="text/javascript" src="../javascripts/jQuery/jquery.validate.js"></script>
- <script type="text/javascript" src="../javascripts/jQuery/jquery.validate.ext.js"></script>
- <script type="text/javascript" src="../javascripts/useraccount/account.js"></script>
- <script type="text/javascript" src="../i18nJavaScript.action"></script>
+ <script type="text/javascript" src="../javascripts/useraccount/restore.js"></script>
<link type="text/css" rel="stylesheet" href="../css/account.css">
</head>
<body>
@@ -25,13 +22,27 @@
<table>
<tr>
- <td style="width:120px"><label for="username">$i18n.getString( "user_name" )</label></td>
+ <td style="width:100px"><label for="username">$i18n.getString( "user_name" )</label></td>
<td><input type="text" id="username" name="username" autocomplete="off"></td>
</tr>
<tr>
<td></td>
- <td><input id="submitButton" type="submit" value="$i18n.getString( 'recover' )" style="width:10em"></td>
+ <td><input id="recoveryButton" type="button" value="$i18n.getString( 'recover' )" style="width:10em" onclick="recoverAccount()"></td>
</tr>
+</table>
+
+</form>
+
+<div id="recoverySuccessMessage" style="display:none">
+Please check your email inbox for this user account. We have sent you instructions
+on how to restore your password.
+</div>
+
+<div id="recoveryErrorMessage" style="display:none">
+Sorry, we were not able to restore your account. The user name might be invalid,
+your account might not permit restore or you might not have entered a valid email
+address for your account.
+</div>
</div>