summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.html2
-rw-r--r--js/codeq/change_password.js50
-rw-r--r--res/en.json2
-rw-r--r--res/sl.json2
4 files changed, 34 insertions, 22 deletions
diff --git a/index.html b/index.html
index 96e7504..0123903 100644
--- a/index.html
+++ b/index.html
@@ -252,6 +252,8 @@
<button type="button" class="btn btn-default" id="change-password-cancel" data-tkey="cancel">Cancel</button>
<button type="submit" class="btn btn-primary" data-tkey="change_password_button">Change password</button>
</div>
+ <span class="error failed" data-tkey="password_change_failed" style="display: none;">Password change failed.</span>
+ <div class="success" data-tkey="password_changed" style="display: none;">Password changed.</div>
</form>
</div>
</div>
diff --git a/js/codeq/change_password.js b/js/codeq/change_password.js
index 6311764..8091a6d 100644
--- a/js/codeq/change_password.js
+++ b/js/codeq/change_password.js
@@ -1,5 +1,5 @@
/* CodeQ: an online programming tutor.
- Copyright (C) 2015 UL FRI
+ Copyright (C) 2015,2016 UL FRI
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free
@@ -14,44 +14,47 @@ details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/**
- * Created by robert on 10/14/15.
- *
- */
-(function(){
+(function () {
"use strict";
var jqScreen = $('#screen-change-password'),
jqChangePassForm = $('#change-password-form'),
jqNew = $('#change-password-new'),
jqVerify = $('#change-password-verify'),
jqCancelBtn = $('#change-password-cancel'),
- jqErrorMismatch = jqChangePassForm.find('.error.mismatch');
+ jqMessages = jqChangePassForm.find('.error,.success'),
+ redirectTimeout = null;
- codeq.globalStateMachine.register('changePassword',{
+ codeq.globalStateMachine.register('changePassword', {
'jqScreen': jqScreen,
'isModal': true,
- 'enter': function() {
- jqErrorMismatch.hide();
+ 'enter': function () {
+ jqChangePassForm.find('button,input').prop('disabled', false);
+ jqMessages.hide();
jqCancelBtn.on('click',function(){
history.back();//forces a transition to the previous state
});
jqChangePassForm.on('submit', function (e) {
- jqErrorMismatch.hide();
+ jqMessages.hide();
if (jqNew.val() != jqVerify.val()) {
- jqErrorMismatch.show();
+ jqChangePassForm.find('.error.mismatch').show();
}
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);
- alert('Password changed.');
- history.back();//force to return to previous state
+ switch (data.code) {
+ case 0:
+ jqChangePassForm.find('button,input').prop('disabled', true);
+ jqChangePassForm.find('.success').show();
+ redirectTimeout = setTimeout(function () {
+ history.back();
+ }, 2000);
+ break;
+ default:
+ jqChangePassForm.find('.error.failed').show();
+ }
})
.fail(function (reason) {
- codeq.log.error('Password change failed: ' + reason, reason);
alert('Password change failed: ' + reason);
})
.done();
@@ -59,12 +62,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
e.preventDefault(); // Prevent the form from submitting via the browser.
});
-
jqScreen.css('display', '');
$('#disabled').css('display', 'none');
},
- 'exit' : function(){
- jqErrorMismatch.hide();
+ 'exit': function () {
+ if (redirectTimeout !== null) {
+ clearTimeout(redirectTimeout);
+ redirectTimeout = null;
+ }
+ jqChangePassForm.find('button,input').prop('disabled', false);
+ jqMessages.hide();
jqChangePassForm.off('submit');
jqCancelBtn.off('click');
jqScreen.css('display', 'none');
@@ -72,5 +79,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqVerify.val('');
}
});
-
})();
diff --git a/res/en.json b/res/en.json
index 5e172c9..fb861c7 100644
--- a/res/en.json
+++ b/res/en.json
@@ -3,6 +3,8 @@
"here": "here",
"language": "Language",
"ui_language_title": "Select the UI language.",
+ "password_change_failed": "Password change failed.",
+ "password_changed": "Password changed.",
"passwords_do_not_match": "Passwords do not match.",
"robot_address": "Robot’s IP address",
"robot_address_placeholder": "IP address",
diff --git a/res/sl.json b/res/sl.json
index e17684a..aebc87f 100644
--- a/res/sl.json
+++ b/res/sl.json
@@ -3,6 +3,8 @@
"here": "tukaj",
"language": "Jezik",
"ui_language_title": "Izberi jezik uporabniškega vmesnika.",
+ "password_change_failed": "Sprememba gesla ni uspela.",
+ "password_changed": "Geslo spremenjeno.",
"passwords_do_not_match": "Gesli se ne ujemata.",
"robot_address": "Robotov naslov IP",
"robot_address_placeholder": "Naslov IP",