← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8644: Added password validation client side

 

------------------------------------------------------------
revno: 8644
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-10-22 18:02:20 +0200
message:
  Added password validation client side
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/commons.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js
  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/account.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.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-22 14:55:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java	2012-10-22 16:02:20 +0000
@@ -170,7 +170,7 @@
             log.info( "Recaptcha failed with code: " + ( results.length > 0 ? results[1] : "" ) );
 
             response.setStatus( HttpServletResponse.SC_BAD_REQUEST );
-            return "The characters you entered did not match the word verification, please try again";
+            return "The characters you entered did not match the word verification, try again";
         }
 
         // ---------------------------------------------------------------------

=== 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-22 11:05:48 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2012-10-22 16:02:20 +0000
@@ -1336,17 +1336,6 @@
 	});
 }
 
-/**
- * Formats validation messages. Used by messages.vm.
- * 
- * @param text the text to format.
- * @returns the formatted text.
- */
-function validatorFormat( text )
-{
-    return $.validator.format( text );
-}
-
 // -----------------------------------------------------------------------------
 // Message
 // -----------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js	2012-10-21 12:56:21 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js	2012-10-22 16:02:20 +0000
@@ -564,3 +564,16 @@
     }
     return null;
 }
+
+function validatorFormat( text ) // Custom code
+{
+    return $.validator.format( text );
+}
+
+jQuery( document ).ready( function() { // Custom code
+	
+	if ( typeof( validationMessage ) !== "undefined"  ) // From messages.vm
+	{
+		$.validator.setMessages( validationMessage );
+	}
+} );
\ No newline at end of file

=== 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-22 14:55:29 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/account.js	2012-10-22 16:02:20 +0000
@@ -2,25 +2,30 @@
 	rules: {
 		firstName: {
 			required: true,
-			rangelength: [ 1, 80 ]
+			rangelength: [ 2, 80 ]
 		},
 		surname: {
 			required: true,
-			rangelength: [ 1, 80 ]
+			rangelength: [ 2, 80 ]
 		},
 		username: {
 			required: true,
-			rangelength: [ 1, 80 ],
+			rangelength: [ 4, 80 ],
 			remote: "../../api/account/username"
 		},
 		password: {
 			required: true,
-			rangelength: [ 1, 80 ]
+			rangelength: [ 8, 80 ],
+			password: true,
+		},
+		retypePassword: {
+			required: true,
+			equalTo: "#password",
 		},
 		email: {
 			required: true,
 			email: true,
-			rangelength: [ 1, 80 ]
+			rangelength: [ 4, 80 ]
 		}
 	}
 };
@@ -31,8 +36,6 @@
 		callback: Recaptcha.focus_response_field
 	} );
 	
-	$( "#recaptchaValidationField" ).hide();
-	
 	$( "#accountForm" ).validate( {
 		rules: validationRules.rules,
 		submitHandler: accountSubmitHandler,
@@ -40,20 +43,22 @@
 			element.parent( "td" ).append( "<br>" ).append( error );
 		}
 	} );
-	
-	$.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"
-	} );
 } );
 
 function accountSubmitHandler()
 {
+	if ( $.trim( $( "#recaptcha_challenge_field" ).val() ).length == 0 ||
+		$.trim( $( "#recaptcha_response_field" ).val() ).length == 0 )
+	{
+		$( "#messageSpan" ).show().text( "Please enter a value for the word verification above" );
+		
+		return false;
+	}
+	
 	$.ajax( {
 		url: "../../api/account",
 		data: $( "#accountForm" ).serialize(),
-		type: "POST",
+		type: "post",
 		success: function( data ) {
 			alert("Account created");
 		},

=== 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-22 14:55:29 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/useraccount/account.vm	2012-10-22 16:02:20 +0000
@@ -4,7 +4,9 @@
     <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="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js";></script>
     <link type="text/css" rel="stylesheet" href="../css/account.css">
 </head>
@@ -20,16 +22,16 @@
 
 <h3>$i18n.getString( "create_new_account" )</h3>
 
-<form id="accountForm" action="../../api/account" method="post">
+<form id="accountForm">
 
 <table>
     <tr>
-        <td><label for="firstName">$i18n.getString( "name" )</label></td>
+        <td style="width:140px"><label for="firstName">$i18n.getString( "name" )</label></td>
         <td><input type="text" id="firstName" name="firstName" style="width:11.7em; margin-right:7px;" placeholder="First">
             <input type="text" id="surname" name="surname" style="width:11.7em" placeholder="Last"></td>
     </tr>
     <tr>
-        <td style="width:140px"><label for="username">$i18n.getString( "user_name" )</label></td>
+        <td><label for="username">$i18n.getString( "user_name" )</label></td>
         <td><input type="text" id="username" name="username" autocomplete="off"></td>
     </tr>
     <tr>

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js	2012-10-22 11:05:48 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js	2012-10-22 16:02:20 +0000
@@ -88,13 +88,6 @@
 	// Intro fade in
 	
 	$( ".introList" ).fadeIn();
-	
-	// Validation
-	
-	if ( typeof( validationMessage ) !== "undefined"  ) // From messages.vm
-	{
-		$.validator.setMessages( validationMessage );
-	}
 }
 
 function setTableStyles()