=== 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 10:20:05 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-10-19 18:29:23 +0000 @@ -41,7 +41,6 @@ import org.springframework.stereotype.Controller; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -62,6 +61,7 @@ private static final String TRUE = "true"; private static final String FALSE = "false"; private static final String SPLIT = "\n"; + private static final int MAX_LENGTH = 80; @Autowired private RestTemplate restTemplate; @@ -99,10 +99,10 @@ // Validate input, return 400 if invalid // --------------------------------------------------------------------- - if ( username == null ) + if ( username == null || username.trim().length() > MAX_LENGTH ) { response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); - return "User name must be specified"; + return "User name is not specified or invalid"; } UserCredentials credentials = userService.getUserCredentialsByUsername( username ); @@ -113,23 +113,29 @@ return "User name is alread taken"; } - if ( firstName == null ) - { - response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); - return "First name must be specified"; - } - - if ( surname == null ) - { - response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); - return "Last name must be specified"; - } - - if ( password == null ) - { - response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); - return "Password must be specified"; - } + if ( firstName == null || firstName.trim().length() > MAX_LENGTH ) + { + response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); + return "First name is not specified or invalid"; + } + + if ( surname == null || surname.trim().length() > MAX_LENGTH ) + { + response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); + return "Last name is not specified or invalid"; + } + + if ( password == null || password.trim().length() > MAX_LENGTH ) + { + response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); + return "Password is not specified or invalid"; + } + + if ( password.trim().equals( username.trim() ) ) + { + response.setStatus( HttpServletResponse.SC_BAD_REQUEST ); + return "Password cannot be equal to username"; + } if ( recapChallenge == null ) { @@ -193,17 +199,15 @@ return "Account created"; } - @RequestMapping( value = "/username/{username}", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_TEXT ) - public @ResponseBody String validateUserName( @PathVariable( "username" ) String username ) + @RequestMapping( value = "/username", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON ) + public @ResponseBody Boolean validateUserName( @RequestParam String username ) { if ( StringUtils.trimToNull( username ) == null ) { - return "Username must be specified"; + return Boolean.FALSE; } - UserCredentials credentials = userService.getUserCredentialsByUsername( username ); - - return credentials == null ? TRUE : "Username is already taken"; + return userService.getUserCredentialsByUsername( username ) == null; } @RequestMapping( value = "/recaptcha", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_TEXT ) === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/account.css' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/account.css 2012-10-19 10:40:09 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/account.css 2012-10-19 18:29:23 +0000 @@ -17,7 +17,7 @@ top: 0; left: 0; width: 100%; - height: 90px; + height: 93px; background-color: #1d5288; } @@ -49,6 +49,13 @@ color: #222; } +label.error +{ + font-weight: normal; + color: red; + font-size: 10pt; +} + input[type=text],input[type=password],textarea { border: 1px solid #aaa; @@ -58,11 +65,11 @@ @font-face { font-family: 'LiberationSansRegular'; - src: url('../../fonts/LiberationSans-Regular-webfont.eot'); - src: url('../../fonts/LiberationSans-Regular-webfont.eot?#iefix') format('eot'), - url('../../fonts/LiberationSans-Regular-webfont.woff') format('woff'), - url('../../fonts/LiberationSans-Regular-webfont.ttf') format('truetype'), - url('../../fonts/LiberationSans-Regular-webfont.svg#webfontc8rbNdBe') format('svg'); + src: url('../fonts/LiberationSans-Regular-webfont.eot'); + src: url('../fonts/LiberationSans-Regular-webfont.eot?#iefix') format('eot'), + url('../fonts/LiberationSans-Regular-webfont.woff') format('woff'), + url('../fonts/LiberationSans-Regular-webfont.ttf') format('truetype'), + url('../fonts/LiberationSans-Regular-webfont.svg#webfontc8rbNdBe') format('svg'); font-weight: normal; font-style: normal; } === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js 2012-10-17 20:29:56 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js 2012-10-19 18:29:23 +0000 @@ -1163,9 +1163,9 @@ // ----------------------------------------------------------------------------- /** - * Create validator for fileds in form * + * Create validator for fileds in form * - * this should replace validation() at some point, but theres just to much code + * This should replace validation() at some point, but theres just to much code * depending on the old version for now. * * See http://bassistance.de/jquery-plugins/jquery-plugin-validation/ for more @@ -1174,27 +1174,31 @@ * @param formId form to validate * @param submitHandler the submitHandler to use * @param kwargs A dictionary of optional arguments, currently supported are: - * beforeValidateHandler rules + * beforeValidateHandler, rules */ -function validation2(formId, submitHandler, kwargs) +function validation2( formId, submitHandler, kwargs ) { var beforeValidateHandler = kwargs["beforeValidateHandler"]; var rules = kwargs["rules"]; - var validator = jQuery("#" + formId ).validate({ - meta:"validate", - errorElement:"span", + var validator = jQuery( "#" + formId ).validate( { + meta: "validate", + errorElement: "span", beforeValidateHandler: beforeValidateHandler, submitHandler: submitHandler, rules: rules, errorPlacement: function(error, element) { - element.parent("td").append("
").append(error); + element.parent( "td" ).append( "
" ).append( error ); } - }); + } ); - $("#" + formId + " input").each(function(n) { - try { - $(this).attr("maxlength", rules[this.id].rangelength[1]); - } catch(e) {} + $( "#" + formId + " input" ).each( function( n ) + { + try + { + $( this ).attr( "maxlength", rules[this.id].rangelength[1] ); + } + catch( e ) + {} }); var nameField = jQuery('#' + formId + ' :input')[0]; === added 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 1970-01-01 00:00:00 +0000 +++ 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 @@ -0,0 +1,51 @@ +var validationRules = { + rules: { + firstName: { + required: true, + rangelength: [ 1, 80 ] + }, + surname: { + required: true, + rangelength: [ 1, 80 ] + }, + username: { + required: true, + rangelength: [ 1, 80 ] + }, + password: { + required: true, + rangelength: [ 1, 80 ], + notequalto : "#username", + }, + retypePassword : { + required: true, + equalTo: "#password" + }, + email: { + required: true, + 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( "
" ).append( error ); + } + } ); + + jQuery.extend( jQuery.validator.messages, { + required: "This field is required", + rangelength: "Please enter a value between 1 and 80 characters long", + email: "Please enter a valid email address" + } ); +} ); \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/account.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/account.vm 2012-10-19 10:20:05 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/account.vm 2012-10-19 18:29:23 +0000 @@ -3,6 +3,8 @@ DHIS 2 + + @@ -17,7 +19,8 @@

Create a new account

-
+ +