ComunicWeb/assets/js/pages/passwordForgotten/promptOption.js

95 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

/**
* 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
*/
2018-07-03 09:39:53 +00:00
_show_options: function(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"
});
securityQuestions.addEventListener("click", function(){
callback("security_questions");
});
}
//Add an option to contact admin (always)
var contact = createElem2({
appendTo: form,
type: "div",
class: "btn btn-default",
2018-05-23 19:14:54 +00:00
innerHTML: "<i class='fa fa-envelope-o'></i> Send a mail to the administration"
});
contact.addEventListener("click", function(){
callback("mail");
});
},
}