diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 0ba46e46..9a947191 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1306,6 +1306,13 @@ var ComunicWeb = { //TODO : implement }, + /** + * Option : prompt security questions + */ + promptSecurityQuestions: { + //TODO : implement + }, + }, /** diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js index c6e9885a..da754ae5 100644 --- a/assets/js/components/account/interface.js +++ b/assets/js/components/account/interface.js @@ -60,6 +60,20 @@ ComunicWeb.components.account.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, + /** + * Given an email address, returns the security questions of a user + * + * @param {String} email The email address of the account + * @param {function} callback + */ + getSecurityQuestions: function(email, callback){ + var apiURI = "account/get_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 da3dc174..dc25ccdc 100644 --- a/assets/js/pages/passwordForgotten/main.js +++ b/assets/js/pages/passwordForgotten/main.js @@ -74,10 +74,16 @@ ComunicWeb.pages.passwordForgotten.main = { emptyElem(boxBody); //Open appropriate page + //Send an email if(option == "mail"){ ComunicWeb.pages.passwordForgotten.mailAdmin.open(email, boxBody); } + //Prompt security questions + else if(option == "security_questions"){ + ComunicWeb.pages.passwordForgotten.promptSecurityQuestions.open(email, boxBody); + } + //Option not recognized else { boxBody.appendChild(ComunicWeb.common.messages.createCalloutElem( diff --git a/assets/js/pages/passwordForgotten/promptOption.js b/assets/js/pages/passwordForgotten/promptOption.js index 64950e4e..1b6907b5 100644 --- a/assets/js/pages/passwordForgotten/promptOption.js +++ b/assets/js/pages/passwordForgotten/promptOption.js @@ -75,6 +75,9 @@ ComunicWeb.pages.passwordForgotten.promptOption = { class: "btn btn-default", innerHTML: " Answer your security questions" }); + securityQuestions.addEventListener("click", function(){ + callback("security_questions"); + }); } //Add an option to contact admin (always) diff --git a/assets/js/pages/passwordForgotten/promptSecurityQuestions.js b/assets/js/pages/passwordForgotten/promptSecurityQuestions.js new file mode 100644 index 00000000..03d6377d --- /dev/null +++ b/assets/js/pages/passwordForgotten/promptSecurityQuestions.js @@ -0,0 +1,54 @@ +/** + * Prompt user security questions + * + * Password reset page + * + * @author Pierre HUBERT + */ + +ComunicWeb.pages.passwordForgotten.promptSecurityQuestions = { + + /** + * Prompt user security questions + * + * @param {String} email The email of the user + * @param {HTMLElement} target The target for the form + */ + open: function(email, target){ + + //Show loading message + target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "Please wait", + "Please wait, we are loading your security questions...", + "info")); + + //Perform a request on the API + ComunicWeb.components.account.interface.getSecurityQuestions(email, function(callback){ + + //Empty target + emptyElem(target); + + //Check for errors + if(callback.error){ + return target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "Error", + "An error occurred while retrieving your security questions...", + "danger")); + } + + //Apply the form + ComunicWeb.pages.passwordForgotten.promptSecurityQuestions._display_form(email, callback.questions, target); + }); + }, + + /** + * Display the security questions input form + * + * @param {String} email The email address of the user + * @param {Array} questions The questions of the user + * @param {HTMLElement} target The target for the form + */ + _display_form: function(email, questions, target){ + console.log(questions); + }, +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 77b1d2d4..8dd55df7 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -418,6 +418,7 @@ class Dev { "js/pages/passwordForgotten/promptEmail.js", "js/pages/passwordForgotten/promptOption.js", "js/pages/passwordForgotten/mailAdmin.js", + "js/pages/passwordForgotten/promptSecurityQuestions.js", //Logout page "js/pages/logout.js",