2018-04-11 08:10:11 +00:00
|
|
|
/**
|
|
|
|
* Create account page
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.pages.createAccount = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open create account page
|
|
|
|
*
|
|
|
|
* @param {Object} additionnalData Additionnal data passed in the method
|
|
|
|
* @param {element} target Where the page will be applied
|
|
|
|
*/
|
|
|
|
openPage: function(additionnalData, target){
|
|
|
|
|
|
|
|
//Display the account creation form
|
|
|
|
this._display_form(target);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the account creation form
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} target The target for the page
|
|
|
|
*/
|
|
|
|
_display_form: function(target){
|
|
|
|
|
|
|
|
//Create form root
|
|
|
|
var formRoot = createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "div",
|
|
|
|
class: "create-account-form"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add a title
|
|
|
|
createElem2({
|
|
|
|
appendTo: formRoot,
|
|
|
|
type: "h2",
|
2018-08-03 12:51:22 +00:00
|
|
|
innerHTML: lang("form_create_account_title")
|
2018-04-11 08:10:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//Add a message
|
|
|
|
createElem2({
|
|
|
|
appendTo: formRoot,
|
|
|
|
type: "p",
|
2018-08-03 12:51:22 +00:00
|
|
|
innerHTML: lang("form_create_account_intro")
|
2018-04-11 08:10:11 +00:00
|
|
|
});
|
|
|
|
|
2018-04-11 08:52:06 +00:00
|
|
|
//Create the message target
|
|
|
|
var messagesTarget = createElem2({
|
|
|
|
appendTo: formRoot,
|
|
|
|
type: "div"
|
|
|
|
});
|
|
|
|
|
2018-04-11 08:10:11 +00:00
|
|
|
//Input user first name
|
|
|
|
var firstNameInput = createFormGroup({
|
|
|
|
target: formRoot,
|
2018-08-03 12:51:22 +00:00
|
|
|
label: lang("form_create_account_first_name_label"),
|
|
|
|
placeholder: lang("form_create_account_first_name_placeholder"),
|
2018-04-11 08:10:11 +00:00
|
|
|
type: "text"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Input user last name
|
|
|
|
var lastNameInput = createFormGroup({
|
|
|
|
target: formRoot,
|
2018-08-03 12:51:22 +00:00
|
|
|
label: lang("form_create_account_last_name_label"),
|
|
|
|
placeholder: lang("form_create_account_last_name_placeholder"),
|
2018-04-11 08:10:11 +00:00
|
|
|
type: "text"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Input user email
|
|
|
|
var emailInput = createFormGroup({
|
|
|
|
target: formRoot,
|
2018-08-03 12:51:22 +00:00
|
|
|
label: lang("form_create_account_email_address_label"),
|
|
|
|
placeholder: lang("form_create_account_email_address_placeholder"),
|
2018-04-11 08:10:11 +00:00
|
|
|
type: "email"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Input user password
|
|
|
|
var passwordInput = createFormGroup({
|
|
|
|
target: formRoot,
|
2018-08-03 13:07:59 +00:00
|
|
|
label: lang("form_create_account_password_label"),
|
|
|
|
placeholder: lang("form_create_account_password_placeholder"),
|
2018-04-11 08:10:11 +00:00
|
|
|
type: "password"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Confirm user password
|
|
|
|
var confirmPasswordInput = createFormGroup({
|
|
|
|
target: formRoot,
|
2018-08-03 13:07:59 +00:00
|
|
|
label: lang("form_create_account_confirm_password_label"),
|
|
|
|
placeholder: lang("form_create_account_confirm_password_placeholder"),
|
2018-04-11 08:10:11 +00:00
|
|
|
type: "password"
|
|
|
|
});
|
|
|
|
|
2018-05-10 13:06:29 +00:00
|
|
|
//Terms of use must have been accepted
|
|
|
|
var siteTerms = createFormGroup({
|
|
|
|
target: formRoot,
|
2018-08-03 13:07:59 +00:00
|
|
|
label: lang("form_create_account_terms_label", [ComunicWeb.__config.aboutWebsiteURL+"about/terms/"]),
|
2018-05-10 13:06:29 +00:00
|
|
|
type: "checkbox"
|
|
|
|
});
|
|
|
|
|
2018-04-11 08:10:11 +00:00
|
|
|
//Submit form
|
|
|
|
var submitButtonContainer = createElem2({
|
|
|
|
appendTo: formRoot,
|
|
|
|
type: "div",
|
|
|
|
class: "submit-form"
|
|
|
|
});
|
|
|
|
var submitButton = createElem2({
|
|
|
|
appendTo: submitButtonContainer,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-primary",
|
2018-08-03 13:07:59 +00:00
|
|
|
innerHTML: lang("form_create_account_submit")
|
2018-04-11 08:10:11 +00:00
|
|
|
});
|
|
|
|
|
2018-04-11 13:56:55 +00:00
|
|
|
//Add bottom links area
|
|
|
|
var bottomLinks = createElem2({
|
|
|
|
appendTo: formRoot,
|
|
|
|
type: "div",
|
|
|
|
class: "bottom-form-links"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Create a link to redirect to the login page
|
|
|
|
var loginLink = createElem2({
|
|
|
|
appendTo: bottomLinks,
|
|
|
|
type: "a",
|
2018-08-03 13:07:59 +00:00
|
|
|
innerHTML: lang("form_create_account_login_with_existing")
|
2018-04-11 13:56:55 +00:00
|
|
|
});
|
|
|
|
loginLink.onclick = function(){
|
|
|
|
openPage("login");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-11 08:52:06 +00:00
|
|
|
//Make the form lives
|
|
|
|
submitButton.onclick = function(){
|
|
|
|
|
|
|
|
//Empty the message target
|
|
|
|
emptyElem(messagesTarget);
|
|
|
|
|
2018-05-10 13:06:29 +00:00
|
|
|
//Check the terms of use have been accepted
|
|
|
|
if(!siteTerms.checked)
|
2018-08-03 13:07:59 +00:00
|
|
|
return notify(lang("form_create_account_err_need_accept_terms"), "danger");
|
2018-05-10 13:06:29 +00:00
|
|
|
|
2018-04-11 08:52:06 +00:00
|
|
|
//Check the first name
|
|
|
|
if(!ComunicWeb.common.formChecker.checkInput(firstNameInput, true))
|
2018-08-03 13:07:59 +00:00
|
|
|
return notify(lang("form_create_account_err_need_first_name"), "danger");
|
2018-04-11 08:52:06 +00:00
|
|
|
|
|
|
|
//Check the last name
|
|
|
|
if(!ComunicWeb.common.formChecker.checkInput(lastNameInput, true))
|
2018-08-03 13:07:59 +00:00
|
|
|
return notify(lang("form_create_account_err_check_last_name"), "danger");
|
2018-04-11 08:52:06 +00:00
|
|
|
|
|
|
|
//Check the email address
|
|
|
|
if(!ComunicWeb.common.formChecker.checkInput(emailInput, true))
|
2018-08-03 13:07:59 +00:00
|
|
|
return notify(lang("form_create_account_err_check_email_address"), "danger");
|
2018-04-11 08:52:06 +00:00
|
|
|
|
|
|
|
//Check the password
|
|
|
|
if(!ComunicWeb.common.formChecker.checkInput(passwordInput, true))
|
2018-08-03 13:07:59 +00:00
|
|
|
return notify(lang("form_create_account_err_check_password"), "danger");
|
2018-04-11 08:52:06 +00:00
|
|
|
|
|
|
|
//Check the confirmation password
|
|
|
|
if(passwordInput.value != confirmPasswordInput.value)
|
2018-08-03 13:07:59 +00:00
|
|
|
return notify(lang("form_create_account_err_passwd_differents"), "danger");
|
2018-04-11 08:52:06 +00:00
|
|
|
|
|
|
|
//Lock create account button
|
|
|
|
submitButton.disabled = true;
|
|
|
|
|
|
|
|
//Try to create the account
|
|
|
|
if(ComunicWeb.components.account.interface.createAccount(
|
|
|
|
firstNameInput.value,
|
|
|
|
lastNameInput.value,
|
|
|
|
emailInput.value,
|
|
|
|
passwordInput.value,
|
|
|
|
function(response){
|
|
|
|
|
|
|
|
//Unlock button
|
|
|
|
submitButton.disabled = false;
|
|
|
|
|
|
|
|
//Check for error
|
|
|
|
if(response.error){
|
|
|
|
//Display an error
|
|
|
|
messagesTarget.appendChild(ComunicWeb.common.messages.createCalloutElem(
|
2018-08-03 13:07:59 +00:00
|
|
|
lang("form_create_account_err_create_account_title"),
|
|
|
|
lang("form_create_account_err_create_account_message"),
|
2018-04-11 08:52:06 +00:00
|
|
|
"danger"
|
|
|
|
));
|
|
|
|
return;
|
|
|
|
}
|
2018-04-11 10:25:50 +00:00
|
|
|
|
|
|
|
//Redirect to the account created page
|
|
|
|
openPage("account_created");
|
2018-04-11 08:52:06 +00:00
|
|
|
}
|
|
|
|
));
|
|
|
|
};
|
|
|
|
},
|
2018-04-11 08:10:11 +00:00
|
|
|
}
|