From 8a02852030716dbdbd64efdd4954ab9ac8f828f9 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Wed, 8 Jun 2016 05:00:16 +0800 Subject: Simple Web UI for changing password Using Bootstrap & jQuery. --- static/juandelacosa.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 static/juandelacosa.js (limited to 'static/juandelacosa.js') 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); + } + }); + }) +}); + -- cgit v1.2.3