diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 96950ff1..0034ace7 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1285,6 +1285,13 @@ var ComunicWeb = { //TODO : implement }, + /** + * Ask user email step + */ + promptEmail: { + //TODO : implement + } + }, /** diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js index 52ee3bbc..46a62f2e 100644 --- a/assets/js/components/account/interface.js +++ b/assets/js/components/account/interface.js @@ -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 * diff --git a/assets/js/pages/passwordForgotten/main.js b/assets/js/pages/passwordForgotten/main.js index 113db40c..c14932d5 100644 --- a/assets/js/pages/passwordForgotten/main.js +++ b/assets/js/pages/passwordForgotten/main.js @@ -60,6 +60,11 @@ ComunicWeb.pages.passwordForgotten.main = { type: "div", class: "box-body" }); + + //Perform first step: ask user his email + ComunicWeb.pages.passwordForgotten.promptEmail.open(boxBody, function(email){ + alert("Email: " + email); + }); }, } \ No newline at end of file diff --git a/assets/js/pages/passwordForgotten/promptEmail.js b/assets/js/pages/passwordForgotten/promptEmail.js new file mode 100644 index 00000000..7e1e6964 --- /dev/null +++ b/assets/js/pages/passwordForgotten/promptEmail.js @@ -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; + } + }, + +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index a8ae1f99..95a7b023 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -413,6 +413,7 @@ class Dev { //Password forgotten page "js/pages/passwordForgotten/main.js", + "js/pages/passwordForgotten/promptEmail.js", //Logout page "js/pages/logout.js",