Prompt user email on password reset

This commit is contained in:
Pierre 2018-05-21 10:40:44 +02:00
parent b0c4971838
commit 683a8eb0e6
5 changed files with 122 additions and 0 deletions

View File

@ -1285,6 +1285,13 @@ var ComunicWeb = {
//TODO : implement //TODO : implement
}, },
/**
* Ask user email step
*/
promptEmail: {
//TODO : implement
}
}, },
/** /**

View File

@ -31,6 +31,20 @@ ComunicWeb.components.account.interface = {
}, },
/**
* Check whether an email address is linked to an account or not
*
* @param {String} email The email address to check
* @param {function} callback
*/
existsMail: function(email, callback){
var apiURI = "account/exists_email";
var params = {
email: email
};
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
* *

View File

@ -60,6 +60,11 @@ ComunicWeb.pages.passwordForgotten.main = {
type: "div", type: "div",
class: "box-body" class: "box-body"
}); });
//Perform first step: ask user his email
ComunicWeb.pages.passwordForgotten.promptEmail.open(boxBody, function(email){
alert("Email: " + email);
});
}, },
} }

View File

@ -0,0 +1,95 @@
/**
* Prompt user email step
*
* @author Pierre HUBERT
*/
ComunicWeb.pages.passwordForgotten.promptEmail = {
/**
* Prompt user email
*
* @param {HTMLElement} target The target for the form
* @param {Function} callback Function to call once the user has entered
* his email
*/
open: function(target, callback){
//Create the form
var form = createElem2({
appendTo: target,
type: "form"
});
//Add message target
var messageTarget = createElem2({
appendTo: form,
type: "div"
});
//Add field
var input = createFormGroup({
target: form,
label: "Your email address",
name: "email",
placeholder: "Email address",
type: "email"
});
//Add submit button
var submit = createElem2({
appendTo: form,
type: "input",
class: "btn btn-primary",
elemType: "submit",
value: "Submit"
});
//Create submit function
var lock = false;
var submit_form = function(){
//Check if the function is locked
if(lock)
return;
//Empty messages target
emptyElem(messageTarget);
//Check given email
if(!ComunicWeb.common.formChecker.checkInput(input, true))
return notify("Please specify a valid email address !", "danger");
//Lock submit button
lock = true;
//Get the email
var email = input.value;
//Check whether the email is linked to an account or not
ComunicWeb.components.account.interface.existsMail(input.value, function(result){
//Unlock the form
lock = false;
//Check if the email is valid
if(!result.exists){
messageTarget.appendChild(ComunicWeb.common.messages.createCalloutElem("Error", "Specified email address not found !", "danger"));
return;
}
//Else the email exists
emptyElem(form);
form.remove();
callback(email);
});
}
//Catch form submission
form.onsubmit = function(){
submit_form();
return false;
}
},
}

View File

@ -413,6 +413,7 @@ class Dev {
//Password forgotten page //Password forgotten page
"js/pages/passwordForgotten/main.js", "js/pages/passwordForgotten/main.js",
"js/pages/passwordForgotten/promptEmail.js",
//Logout page //Logout page
"js/pages/logout.js", "js/pages/logout.js",