From 9b32ee19e862f163fd31661b34807a995b1d89b2 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 18 Apr 2018 18:33:18 +0200 Subject: [PATCH] Perform a request over the API to fetch security information --- .../css/pages/settings/sections/security.css | 25 ++++++ assets/js/components/settings/interface.js | 16 +++- assets/js/pages/settings/sections/security.js | 79 ++++++++++++++++++- 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/assets/css/pages/settings/sections/security.css b/assets/css/pages/settings/sections/security.css index 8ec419da..f54be90e 100644 --- a/assets/css/pages/settings/sections/security.css +++ b/assets/css/pages/settings/sections/security.css @@ -2,4 +2,29 @@ * Security settings section * * @author Pierre HUBERT + */ + + +/** + * Prompt user password box + */ +.box-security-settings .prompt-user-password h4, +.box-security-settings .prompt-user-password p { + text-align: center; +} + +.box-security-settings .prompt-user-password label { + display: none; +} + +.box-security-settings .prompt-user-password .submit-form { + width: 100px; + margin: auto; + display: block; +} + + + +/** + * Global box rules */ \ No newline at end of file diff --git a/assets/js/components/settings/interface.js b/assets/js/components/settings/interface.js index fc5c7f90..d988a739 100644 --- a/assets/js/components/settings/interface.js +++ b/assets/js/components/settings/interface.js @@ -43,6 +43,20 @@ ComunicWeb.components.settings.interface = { directory: directory }; ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); - } + }, + + /** + * Get security account settings + * + * @param {string} password The password of the user + * @param {function} callback Callback function + */ + getSecurity: function(password, callback){ + var apiURI = "settings/get_security"; + var params = { + password: password + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, } \ No newline at end of file diff --git a/assets/js/pages/settings/sections/security.js b/assets/js/pages/settings/sections/security.js index 3c7f315d..772a4ee7 100644 --- a/assets/js/pages/settings/sections/security.js +++ b/assets/js/pages/settings/sections/security.js @@ -41,7 +41,84 @@ ComunicWeb.pages.settings.sections.security = { class: "box-body" }); - + //Append the form to query user password + this._append_form_prompt_user_password(boxBody); }, + /** + * Append a form to prompt user password + * + * @param {HMTLElement} target The target for the form + */ + _append_form_prompt_user_password: function(target){ + + //Create form contener (allows easier manipulations then) + var formContener = createElem2({ + appendTo: target, + type: "div", + class: "prompt-user-password" + }); + + //Add title + createElem2({ + appendTo: formContener, + type: "h4", + innerHTML: "Password required" + }); + + //Add explanation + createElem2({ + appendTo: formContener, + type: "p", + innerHTML: "In order to protect these sensitive information, your password is required to access this page." + }); + + //User password form + var passwordInput = createFormGroup({ + target: formContener, + label: "Your password", + placeholder: "Your password", + type: "password" + }); + + //Add submit button + var sendButton = createElem2({ + appendTo: formContener, + type: "div", + class: "btn btn-primary submit-form", + innerHTML: "Submit" + }); + + //Make submit button lives + sendButton.onclick = function(){ + + //Check the validity of the input + if(!ComunicWeb.common.formChecker.checkInput(passwordInput, true)){ + notify("Please input your password !", "danger"); + return; + } + + //Hide send button + sendButton.style.visibility = "hide"; + + //Perform a request over the server to fetch security settings + ComunicWeb.components.settings.interface.getSecurity(passwordInput.value, function(result){ + + //Show send button + sendButton.style.visibility = "visible"; + + //Check for errors + if(result.error){ + notify("An error occured while retrieving security settings! Please check your password...", "danger"); + return; + } + + //Remove password input form + emptyElem(formContener); + + //Show security information update form + + }); + }; + }, } \ No newline at end of file