diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2016-06-08 05:00:16 +0800 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2016-06-08 23:42:31 +0800 |
commit | 8a02852030716dbdbd64efdd4954ab9ac8f828f9 (patch) | |
tree | 690a216e08f4a2d97dfe80886fd2053f4283c4b0 /static/juandelacosa.js | |
parent | 50fbf638a92b0dfc85b9000bc026911f798dede8 (diff) | |
download | juandelacosa-8a02852030716dbdbd64efdd4954ab9ac8f828f9.tar.gz |
Simple Web UI for changing password
Using Bootstrap & jQuery.
Diffstat (limited to 'static/juandelacosa.js')
-rw-r--r-- | static/juandelacosa.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/static/juandelacosa.js b/static/juandelacosa.js new file mode 100644 index 0000000..b4be44f --- /dev/null +++ b/static/juandelacosa.js @@ -0,0 +1,69 @@ +$(function () { + var account = $('#account'); + var main = $('#main'); + var noSuchAccount = $('#noSuchAccount'); + var password = $('#password'); + var passwordChanged = $('#passwordChanged'); + var passwordFailed = $('#passwordFailed'); + var resetPassword = $('#resetPassword'); + + document.title = window.location.hostname + ' - ' + 'Juan De La Cosa'; + + (function whoAmI() { + $.ajax({ + url: "whoAmI", + method: "GET", + success: function (login) { + noSuchAccount.hide(); + main.show(); + $('#login').val(login); + }, + error: function (jqXHR, textStatus, errorThrown) { + if (404 == jqXHR.status) { + main.hide(); + account.text(jqXHR.responseText); + noSuchAccount.show(); + } + }, + complete: setTimeout(whoAmI, 60 * 1000) + }) + })(); + + resetPassword.click(function () { + $.ajax({ + url: "resetMyPassword", + method: "POST", + error: function (jqXHR, textStatus, errorThrown) { + resetPassword.prop('disabled', true); + passwordFailed.fadeIn(); + if (0 == jqXHR.readyState) { + passwordFailed.text('Service unavailable'); + } else { + passwordFailed.text(errorThrown); + } + setTimeout(function () { + passwordFailed.fadeOut(); + resetPassword.prop('disabled', false); + }, 5 * 1000); + }, + success: function (newpwd) { + resetPassword.hide(); + password.val(newpwd); + password.show(); + passwordChanged.fadeIn(); + password.select(); + + setTimeout(function () { + passwordChanged.fadeOut(); + }, 5 * 1000); + + setTimeout(function () { + password.val(''); + password.hide(); + resetPassword.show(); + }, 10 * 1000); + } + }); + }) +}); + |