From cd612c54926ea3b0d2400a3ca9e4e9e8babcfaff Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 1 Mar 2016 18:07:55 +0100 Subject: change_password: do not use alerts in normal operation --- index.html | 2 ++ js/codeq/change_password.js | 50 +++++++++++++++++++++++++-------------------- res/en.json | 2 ++ res/sl.json | 2 ++ 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 @@ + + 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 . */ - - -/** - * 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 . */ 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 . */ 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", -- cgit v1.2.1