diff options
author | Marko Pušnik <marko.pusnik@guru.si> | 2015-10-12 11:52:00 +0200 |
---|---|---|
committer | Marko Pušnik <marko.pusnik@guru.si> | 2015-10-12 11:52:00 +0200 |
commit | 894df8afb3c70f2b17437d10d43a7b62402f59c3 (patch) | |
tree | 653d57072a307c2ec10223310f180385e7beb67a | |
parent | 3c03af39297f47af09def0cacba5190b0081a718 (diff) |
ResetPassword: form validation
-rw-r--r-- | index.html | 10 | ||||
-rw-r--r-- | js/codeq/profile.js | 50 |
2 files changed, 35 insertions, 25 deletions
@@ -351,7 +351,7 @@ <h3 class="text-center">Sign up</h3> </div> <div class="modal-body"> - <form id="formSignUp" class="form" action=""> + <form id="formSignUp" class="form"> <div class="form-group"> <label class="control-label small">Username</label> <input class="form-control" name="username" id="modalSignUpUsername" type="text" placeholder="desired username" pattern="^[a-z,A-Z,0-9,_]{5,15}$" data-valid-min="5" title="Choose a alpha-numeric username of 5-15 characters" required=""> @@ -390,20 +390,20 @@ <h3 class="text-center">Change password </h3> </div> <div class="modal-body"> - <form class="form" method="post"> + <form id="formChangePassword" class="form"> <div class="form-group"> <label class="control-label small">New Password</label> - <input class="form-control" placeholder="Enter a new password" name="new" id="modalChangePasswordNew" type="password"> + <input class="form-control" placeholder="Enter a new password" name="new" id="modalChangePasswordNew" type="password" pattern="^[a-z,A-Z,0-9,_]{6,}$" data-valid-min="6" title="Choose a alpha-numeric password of a least 6 characters" required=""> </div> <div class="form-group"> <label class="control-label small">Verify Password</label> - <input class="form-control" placeholder="Repeat the password again" name="verify" id="modalChangePasswordVerify" type="password"> + <input class="form-control" placeholder="Repeat the password again" name="verify" id="modalChangePasswordVerify" type="password" pattern="^[a-z,A-Z,0-9,_]{6,}$" data-valid-min="6" title="Choose a alpha-numeric password of a least 6 characters" required=""> </div> </form><!--/row--> </div><!--/modal-body--> <div class="modal-footer"> <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button> - <button class="btn btn-primary" id="btnPasswdChange" type="submit" onclick="codeq.profile.changePassword()">Change</button> + <input form="formChangePassword" class="btn btn-primary" id="btnPasswdChange" type="submit" value="Change password"></button> </div><!--/modal-footer--> </div> </div> diff --git a/js/codeq/profile.js b/js/codeq/profile.js index 687a3c7..2759be3 100644 --- a/js/codeq/profile.js +++ b/js/codeq/profile.js @@ -18,6 +18,8 @@ else {
codeq.comms.signup(jqUsername.val(), jqName.val(), jqEmail.val(), jqPassword.val())
.then(function (data) {
+ if (data.code !== 0) throw new Error('Signup failed, code: ' + data.code + ', message: ' + data.message);
+
//back to login
$('#modalSignUp').modal('hide');
alert('Welcome '+ jqUsername.val() +'. Thanks for signing up.');
@@ -31,34 +33,42 @@ jqPassword.val('');
jqVerify.val('');
})
+ .fail(function (reason) {
+ codeq.log.error('Signup failed: ' + reason, reason);
+ alert('Signup failed: ' + reason);
+ })
.done();
}
event.preventDefault(); // Prevent the form from submitting via the browser.
});
- codeq.profile = {
+ $('#formChangePassword').submit(function(event) {
+ var jqNew = $("#modalChangePasswordNew"),
+ jqVerify = $("#modalChangePasswordVerify");
- 'changePassword': function () {
- var jqNew = $("#modalChangePasswordNew"),
- jqVerify = $("#modalChangePasswordVerify");
+ if (jqNew.val() != jqVerify.val()) {
+ alert('Passwords do not match.');
+ }
+ else {
+ codeq.comms.changePassword(jqNew.val())
+ .then(function (data) {
+ if (data.code !== 0) throw new Error('Password change failed, code: ' + data.code + ', message: ' + data.message);
- if (jqNew.val() == "" || jqVerify.val() == "") {
- alert('Some fields are empty.');
- }
- else if (jqNew.val() != jqVerify.val()) {
- alert('Passwords do not match.');
- }
- else {
- codeq.comms.changePassword(jqNew.val())
- .then(function (data) {
- $('#modalChangePassword').modal('hide');
- jqNew.val('');
- jqVerify.val('');
- alert('Password changed.');
- })
- .done();
- }
+ $('#modalChangePassword').modal('hide');
+ jqNew.val('');
+ jqVerify.val('');
+ alert('Password changed.');
+ })
+ .fail(function (reason) {
+ codeq.log.error('Password change failed: ' + reason, reason);
+ alert('Password change failed: ' + reason);
+ })
+ .done();
}
+ event.preventDefault(); // Prevent the form from submitting via the browser.
+ });
+
+ codeq.profile = {
};
codeq.globalStateMachine.register('profile',{
|