summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMarko Pušnik <marko.pusnik@guru.si>2015-10-12 11:52:00 +0200
committerMarko Pušnik <marko.pusnik@guru.si>2015-10-12 11:52:00 +0200
commit894df8afb3c70f2b17437d10d43a7b62402f59c3 (patch)
tree653d57072a307c2ec10223310f180385e7beb67a /js
parent3c03af39297f47af09def0cacba5190b0081a718 (diff)
ResetPassword: form validation
Diffstat (limited to 'js')
-rw-r--r--js/codeq/profile.js50
1 files changed, 30 insertions, 20 deletions
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',{