mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 12:09:21 +00:00
Security questions form now lives
This commit is contained in:
parent
f5638c3196
commit
e0d5e50357
@ -74,6 +74,37 @@ ComunicWeb.components.account.interface = {
|
|||||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get passowrd reset token using security answer
|
||||||
|
*
|
||||||
|
* @param {String} email The email address of the account
|
||||||
|
* @param {Array} answers The answers to the security questions
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
resetPasswordWithSecurityAnswers: function(email, answers, callback){
|
||||||
|
|
||||||
|
//Prepare answers
|
||||||
|
answersText = "";
|
||||||
|
answers.forEach(function(answer){
|
||||||
|
|
||||||
|
if(answersText != "")
|
||||||
|
answersText += "&";
|
||||||
|
|
||||||
|
answersText += encodeURIComponent(answer);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//Perform the request
|
||||||
|
var apiURI = "account/check_security_answers";
|
||||||
|
var params = {
|
||||||
|
email: email,
|
||||||
|
answers: answersText
|
||||||
|
};
|
||||||
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the export of all the data of the user
|
* Request the export of all the data of the user
|
||||||
*
|
*
|
||||||
|
@ -49,6 +49,89 @@ ComunicWeb.pages.passwordForgotten.promptSecurityQuestions = {
|
|||||||
* @param {HTMLElement} target The target for the form
|
* @param {HTMLElement} target The target for the form
|
||||||
*/
|
*/
|
||||||
_display_form: function(email, questions, target){
|
_display_form: function(email, questions, target){
|
||||||
console.log(questions);
|
|
||||||
|
//Create form target
|
||||||
|
var form = createElem2({
|
||||||
|
appendTo: target,
|
||||||
|
type: "div"
|
||||||
|
});
|
||||||
|
|
||||||
|
//Add messages target
|
||||||
|
var messagesTarget = createElem2({
|
||||||
|
appendTo: form,
|
||||||
|
type: "div"
|
||||||
|
});
|
||||||
|
|
||||||
|
//Add notice
|
||||||
|
add_p(form, "Please answer your security questions now, in order to reset your password.");
|
||||||
|
add_p(form, "Do not worry about lowercase and uppercase letters.");
|
||||||
|
|
||||||
|
//Process the questions
|
||||||
|
var inputs = [];
|
||||||
|
|
||||||
|
questions.forEach(function(question){
|
||||||
|
|
||||||
|
//Create the input
|
||||||
|
var input = createFormGroup({
|
||||||
|
target: form,
|
||||||
|
label: question,
|
||||||
|
placeholder: "Your answer to the question",
|
||||||
|
type: "text"
|
||||||
|
});
|
||||||
|
inputs.push(input);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//Add submit button
|
||||||
|
var submit = createElem2({
|
||||||
|
appendTo: form,
|
||||||
|
type: "div",
|
||||||
|
class: "btn btn-primary",
|
||||||
|
innerHTML: "Submit"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//Make submit button lives
|
||||||
|
submit.addEventListener("click", function(e){
|
||||||
|
|
||||||
|
//Check if another request is already pending
|
||||||
|
if(submit.disabled) return;
|
||||||
|
|
||||||
|
//Check the inputs
|
||||||
|
var answers = [];
|
||||||
|
inputs.forEach(function(input){
|
||||||
|
answers.push(input.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
//Send a request to the server
|
||||||
|
submit.disabled = true;
|
||||||
|
|
||||||
|
//Add loading message
|
||||||
|
emptyElem(messagesTarget);
|
||||||
|
messagesTarget.appendChild(ComunicWeb.common.messages.createCalloutElem(
|
||||||
|
"Loading",
|
||||||
|
"Please wait while we are checking your security answers...",
|
||||||
|
"info"));
|
||||||
|
|
||||||
|
ComunicWeb.components.account.interface.resetPasswordWithSecurityAnswers(email, answers, function(result){
|
||||||
|
|
||||||
|
submit.disabled = false;
|
||||||
|
emptyElem(messagesTarget);
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if(result.error){
|
||||||
|
messagesTarget.appendChild(ComunicWeb.common.messages.createCalloutElem(
|
||||||
|
"Error",
|
||||||
|
"The server rejected your security answers, please check them...",
|
||||||
|
"danger"
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Redirect to reset page
|
||||||
|
openPage("reset_password?token=#" + result.reset_token);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user