diff --git a/css/setpassword.css b/css/setpassword.css index 67cd2ff..69c1342 100644 --- a/css/setpassword.css +++ b/css/setpassword.css @@ -13,3 +13,11 @@ #password { width: 100%; } + +#retypepassword { + width: 100%; +} + +#message { + width: 94%; +} diff --git a/js/setpassword.js b/js/setpassword.js index 9477fb5..330eb61 100644 --- a/js/setpassword.js +++ b/js/setpassword.js @@ -5,17 +5,28 @@ }, onClickSetPassword : function(event){ - event.preventDefault(); var passwordObj = $('#password'); - if (passwordObj.val()){ + var retypePasswordObj = $('#retypepassword'); + passwordObj.parent().removeClass('shake'); + event.preventDefault(); + if (passwordObj.val() === retypePasswordObj.val()) { $.post( passwordObj.parents('form').attr('action'), - {password : passwordObj.val()} + {password: passwordObj.val()} ).done(function (result) { OCA.UserManagement.SetPassword._resetDone(result); }).fail(function (result) { OCA.UserManagement.SetPassword._onSetPasswordFail(result); }); + } else { + //Password mismatch happened + passwordObj.val(''); + retypePasswordObj.val(''); + passwordObj.parent().addClass('shake'); + $('#message').addClass('warning'); + $('#message').text('Passwords do not match'); + $('#message').show(); + passwordObj.focus(); } }, @@ -59,4 +70,14 @@ $(document).ready(function () { OCA.UserManagement.SetPassword.init(); + $('#password').keypress(function () { + /* + The warning message should be shown only during password mismatch. + Else it should not. + */ + if (($('#password').val().length >= 0) && ($('#retypepassword').val().length === 0)) { + $('#message').removeClass('warning'); + $('#message').text(''); + } + }); }); diff --git a/templates/new_user/setpassword.php b/templates/new_user/setpassword.php index c2e0798..2f427e3 100644 --- a/templates/new_user/setpassword.php +++ b/templates/new_user/setpassword.php @@ -25,12 +25,17 @@
-

+

+ +

' + + '' + + ' />' + + '' + '

' + '' + @@ -47,6 +51,7 @@ describe('OCA.UserManagement.SetPassword tests', function () { SetPassword.init(); $('#password').val('foo'); + $('#retypepassword').val('foo'); $('#submit').click(); expect(resultSpy.calledOnce).toEqual(true); @@ -63,6 +68,7 @@ describe('OCA.UserManagement.SetPassword tests', function () { SetPassword.init(); $('#password').val('foo'); + $('#retypepassword').val('foo'); $('#submit').click(); expect(resultSpy.calledOnce).toEqual(true);