From 9a7c3245c4666a82baa31ba1b7011b6f4c180951 Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 22 May 2018 22:48:48 +0200 Subject: [PATCH] Prompt user preferred option to reset its password --- .../pages/passwordForgotten/promptOption.css | 14 +++ assets/js/common/functionsSchema.js | 9 +- assets/js/components/account/interface.js | 15 ++++ assets/js/pages/passwordForgotten/main.js | 11 ++- .../pages/passwordForgotten/promptOption.js | 89 +++++++++++++++++++ system/config/dev.config.php | 4 +- 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 assets/css/pages/passwordForgotten/promptOption.css create mode 100644 assets/js/pages/passwordForgotten/promptOption.js diff --git a/assets/css/pages/passwordForgotten/promptOption.css b/assets/css/pages/passwordForgotten/promptOption.css new file mode 100644 index 00000000..643cb73b --- /dev/null +++ b/assets/css/pages/passwordForgotten/promptOption.css @@ -0,0 +1,14 @@ +/** + * Password forgotten prompt option section stylesheet + * + * @author Pierre HUBERT + */ + +.password-reset-prompt-option-section p { + text-align: justify; +} + +.password-reset-prompt-option-section .btn { + width: 100%; + margin-top: 10px; +} \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 0034ace7..aa768738 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1290,7 +1290,14 @@ var ComunicWeb = { */ promptEmail: { //TODO : implement - } + }, + + /** + * Ask user reset option + */ + promptOption: { + //TODO : implement + }, }, diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js index 46a62f2e..c6e9885a 100644 --- a/assets/js/components/account/interface.js +++ b/assets/js/components/account/interface.js @@ -45,6 +45,21 @@ ComunicWeb.components.account.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, + /** + * Check whether the security questions have been set for an account + * with an email address or not + * + * @param {String} email The email address of the account + * @param {function} callback + */ + checkSecurityQuestionsExistence: function(email, callback){ + var apiURI = "account/has_security_questions"; + var params = { + email: email + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, + /** * Request the export of all the data of the user * diff --git a/assets/js/pages/passwordForgotten/main.js b/assets/js/pages/passwordForgotten/main.js index c14932d5..8ab07e0e 100644 --- a/assets/js/pages/passwordForgotten/main.js +++ b/assets/js/pages/passwordForgotten/main.js @@ -63,7 +63,16 @@ ComunicWeb.pages.passwordForgotten.main = { //Perform first step: ask user his email ComunicWeb.pages.passwordForgotten.promptEmail.open(boxBody, function(email){ - alert("Email: " + email); + + //Empty body + emptyElem(boxBody); + + //Prompt user reset option + ComunicWeb.pages.passwordForgotten.promptOption.open(email, boxBody, function(option){ + + alert(option); + + }); }); }, diff --git a/assets/js/pages/passwordForgotten/promptOption.js b/assets/js/pages/passwordForgotten/promptOption.js new file mode 100644 index 00000000..b489e7ce --- /dev/null +++ b/assets/js/pages/passwordForgotten/promptOption.js @@ -0,0 +1,89 @@ +/** + * Prompt user option to reset his password page + * + * @author Pierre HUBERT + */ + +ComunicWeb.pages.passwordForgotten.promptOption = { + + /** + * Open prompt option page + * + * @param {String} email Target email address + * @param {HTMLElement} target The target of the parameter + * @param {Function} callback + */ + open: function(email, target, callback){ + + //Display loading message + createElem2({ + appendTo: target, + type: "p", + innerHTML: "Please wait, we are checking available options..." + }); + + //Check if security questions have been set on this account + ComunicWeb.components.account.interface.checkSecurityQuestionsExistence(email, function(result){ + + emptyElem(target); + + //Check for errors + if(result.error){ + target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "An error occurred.", + "An error occurred while retrieving available options. Please try to refresh the page and start again.", + "danger")); + return; + } + + //Display available options to the user + ComunicWeb.pages.passwordForgotten.promptOption._show_options(result.defined, target, callback); + }); + + + }, + + /** + * Display options to the user + * + * @param {Boolean} hasSecurityQuestions Specify wether the user can use security + * questions to reset his password or not + * @param {HTMLElement} target The target of the form + * @param {Function} callback + */ + _show_options(hasSecurityQuestions, target, callback){ + + //Create a form + var form = createElem2({ + type: "div", + class: "password-reset-prompt-option-section", + appendTo: target + }); + + //Message + createElem2({ + appendTo: form, + type: "p", + innerHTML: "Here are your available options to reset your password:" + }); + + if(hasSecurityQuestions){ + //Add an option to answer security questions (if available) + var securityQuestions = createElem2({ + appendTo: form, + type: "div", + class: "btn btn-default", + innerHTML: " Answer your security questions" + }); + } + + //Add an option to contact admin (always) + var contact = createElem2({ + appendTo: form, + type: "div", + class: "btn btn-default", + innerHTML: " Contact the administration" + }); + }, + +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 95a7b023..64b800b8 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -227,7 +227,8 @@ class Dev { "css/pages/createAccount.css", //Password forgotten page - "css/pages/passwordForgotten/main.css" + "css/pages/passwordForgotten/main.css", + "css/pages/passwordForgotten/promptOption.css" ); /** @@ -414,6 +415,7 @@ class Dev { //Password forgotten page "js/pages/passwordForgotten/main.js", "js/pages/passwordForgotten/promptEmail.js", + "js/pages/passwordForgotten/promptOption.js", //Logout page "js/pages/logout.js",