dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19624
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8641: Remote validation of account username
------------------------------------------------------------
revno: 8641
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-10-22 13:30:52 +0200
message:
Remote validation of account username
modified:
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
--
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-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-19 18:29:23 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-10-22 11:30:52 +0000
@@ -200,14 +200,14 @@
}
@RequestMapping( value = "/username", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
- public @ResponseBody Boolean validateUserName( @RequestParam String username )
+ public @ResponseBody String validateUserName( @RequestParam String username )
{
- if ( StringUtils.trimToNull( username ) == null )
- {
- return Boolean.FALSE;
- }
-
- return userService.getUserCredentialsByUsername( username ) == null;
+ boolean valid = username != null && userService.getUserCredentialsByUsername( username ) == null;
+
+ // Custom code required because of our hacked jQuery validation
+
+ return valid ? "{ \"response\": \"success\", \"message\": \"\" }" :
+ "{ \"response\": \"error\", \"message\": \"Username is already taken\" }";
}
@RequestMapping( value = "/recaptcha", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_TEXT )
@@ -249,5 +249,5 @@
log.info( "Recaptcha result: " + result );
return result != null ? result.split( SPLIT ) : null;
- }
+ }
}
=== 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-19 18:29:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/account.js 2012-10-22 11:30:52 +0000
@@ -10,7 +10,8 @@
},
username: {
required: true,
- rangelength: [ 1, 80 ]
+ rangelength: [ 1, 80 ],
+ remote: "../../api/account/username"
},
password: {
required: true,
@@ -26,18 +27,12 @@
email: true,
rangelength: [ 1, 80 ]
}
- },
- messages: {
- username: {
- remote: "Username is already taken"
- }
}
};
$( document ).ready( function() {
jQuery( "#accountForm" ).validate( {
rules: validationRules.rules,
- messages: validationRules.messages,
errorPlacement: function( error, element ) {
element.parent( "td" ).append( "<br>" ).append( error );
}