Prompt user preferred option to reset its password

This commit is contained in:
Pierre 2018-05-22 22:48:48 +02:00
parent 79da14e0bc
commit 9a7c3245c4
6 changed files with 139 additions and 3 deletions

View File

@ -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;
}

View File

@ -1290,7 +1290,14 @@ var ComunicWeb = {
*/
promptEmail: {
//TODO : implement
}
},
/**
* Ask user reset option
*/
promptOption: {
//TODO : implement
},
},

View File

@ -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
*

View File

@ -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);
});
});
},

View File

@ -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: "<i class='fa fa-question'></i> Answer your security questions"
});
}
//Add an option to contact admin (always)
var contact = createElem2({
appendTo: form,
type: "div",
class: "btn btn-default",
innerHTML: "<i class='fa fa-envelope-o'></i> Contact the administration"
});
},
}

View File

@ -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",