diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-03 10:35:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-03 10:35:14 +0100 |
commit | 0d74357b78e6cc958e41808ff1b1af287258629e (patch) | |
tree | faa7ff523a3455420ac797ca540f76d9705f0894 | |
parent | 362ccbd041085e19dab908ad2a03eb90cf057b98 (diff) | |
parent | 626fe0339c3dee9c9a909fa4f42bd4c92cb851b5 (diff) | |
download | rspamd-0d74357b78e6cc958e41808ff1b1af287258629e.tar.gz rspamd-0d74357b78e6cc958e41808ff1b1af287258629e.zip |
Merge pull request #2558 from moisseev/eslint
[WebUI] Do not display password form when secure_ip is set
-rw-r--r-- | interface/index.html | 4 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 103 |
2 files changed, 53 insertions, 54 deletions
diff --git a/interface/index.html b/interface/index.html index 1cf363b96..8d40da510 100644 --- a/interface/index.html +++ b/interface/index.html @@ -357,11 +357,11 @@ </div> <!-- login modal --> -<div id="connectDialog" class="modal" tabindex="-1" role="dialog" aria-labelledby="RSPAMD Connect"> +<div id="connectDialog" class="modal" tabindex="-1" role="dialog" style="display:none"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> - <h3>RSPAMD Connect</h3> + <h3>Login to Rspamd</h3> </div> <div class="modal-body" id="connectBody"> <form id="connectForm"> diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index fde541285..29bbfbcf1 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -134,13 +134,6 @@ function ($, D3pie, visibility, NProgress, tab_stat, tab_graph, tab_config, sessionStorage.setItem("Password", password); } - function isLogged() { - if (sessionStorage.getItem("Credentials") !== null) { - return true; - } - return false; - } - function displayUI() { // In many browsers local storage can only store string. // So when we store the boolean true or false, it actually stores the strings "true" or "false". @@ -300,53 +293,59 @@ function ($, D3pie, visibility, NProgress, tab_stat, tab_graph, tab_config, }; ui.connect = function () { - if (isLogged()) { - displayUI(); - return; - } - - var dialog = $("#connectDialog"); - var backdrop = $("#backDrop"); - $("#mainUI").hide(); - $(dialog).show(); - $(backdrop).show(); - $("#connectPassword").focus(); - $("#connectForm").off("submit"); - - $("#connectForm").on("submit", function (e) { - e.preventDefault(); - var password = $("#connectPassword").val(); - if (!(/^[\u0020-\u007e]*$/).test(password)) { - alertMessage("alert-modal alert-error", "Invalid characters in the password"); + // Query "/stat" to check if user is already logged in or client ip matches "secure_ip" + $.ajax({ + type: "GET", + url: "stat", + async: false, + success: function () { + displayUI(); + }, + error: function () { + var dialog = $("#connectDialog"); + var backdrop = $("#backDrop"); + $("#mainUI").hide(); + $(dialog).show(); + $(backdrop).show(); $("#connectPassword").focus(); - return; - } - - ui.query("auth", { - headers: { - Password: password - }, - success: function (json) { - var data = json[0].data; - $("#connectPassword").val(""); - if (data.auth === "ok") { - sessionStorage.setItem("read_only", data.read_only); - saveCredentials(password); - $(dialog).hide(); - $(backdrop).hide(); - displayUI(); + $("#connectForm").off("submit"); + + $("#connectForm").on("submit", function (e) { + e.preventDefault(); + var password = $("#connectPassword").val(); + if (!(/^[\u0020-\u007e]*$/).test(password)) { + alertMessage("alert-modal alert-error", "Invalid characters in the password"); + $("#connectPassword").focus(); + return; } - }, - error: function (jqXHR) { - ui.alertMessage("alert-modal alert-error", jqXHR.statusText); - $("#connectPassword").val(""); - $("#connectPassword").focus(); - }, - params: { - global: false, - }, - server: "local" - }); + + ui.query("auth", { + headers: { + Password: password + }, + success: function (json) { + var data = json[0].data; + $("#connectPassword").val(""); + if (data.auth === "ok") { + sessionStorage.setItem("read_only", data.read_only); + saveCredentials(password); + $(dialog).hide(); + $(backdrop).hide(); + displayUI(); + } + }, + error: function (jqXHR) { + ui.alertMessage("alert-modal alert-error", jqXHR.statusText); + $("#connectPassword").val(""); + $("#connectPassword").focus(); + }, + params: { + global: false, + }, + server: "local" + }); + }); + } }); }; |