mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 01:48:50 +00:00
Send a request to create an account on the server
This commit is contained in:
parent
99adb1ec0a
commit
7015e10dd3
@ -21,6 +21,10 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.create-account-form .callout p {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
.create-account-form .submit-form {
|
||||
text-align: center;
|
||||
}
|
@ -441,6 +441,20 @@ var ComunicWeb = {
|
||||
*/
|
||||
components: {
|
||||
|
||||
/**
|
||||
* Account component
|
||||
*/
|
||||
account: {
|
||||
|
||||
/**
|
||||
* Interface
|
||||
*/
|
||||
interface: {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Menubar
|
||||
*/
|
||||
|
@ -111,4 +111,16 @@ function openConversation(id){
|
||||
ComunicWeb.components.conversations.manager.addConversation({
|
||||
conversationID: id
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notification
|
||||
*
|
||||
* @param {string} message The message of the notification
|
||||
* @param {string} type The type of the notification (danger, info, success, primary)
|
||||
* @param {number} duration The notification duration
|
||||
* @param {string} title The title of the notification
|
||||
*/
|
||||
function notify(message, type, duration, title){
|
||||
ComunicWeb.common.notificationSystem.showNotification(message, type, duration, title)
|
||||
}
|
34
assets/js/components/account/interface.js
Normal file
34
assets/js/components/account/interface.js
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Account interface
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.components.account.interface = {
|
||||
|
||||
/**
|
||||
* Send a request on the server to create an account
|
||||
*
|
||||
* @param {string} firstName The first name of the user
|
||||
* @param {string} lastName The last name of the user
|
||||
* @param {email} emailAddress The email adress of the user
|
||||
* @param {password} password The password of the user
|
||||
* @param {callback} callback The callback function
|
||||
*/
|
||||
createAccount: function(firstName, lastName, emailAddress, password, callback){
|
||||
|
||||
//Make an API request
|
||||
var apiURI = "account/create";
|
||||
var params = {
|
||||
"firstName": firstName,
|
||||
"lastName": lastName,
|
||||
"emailAddress": emailAddress,
|
||||
"password": password
|
||||
};
|
||||
|
||||
//Perform an API request
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, false, callback);
|
||||
|
||||
},
|
||||
|
||||
}
|
@ -47,6 +47,12 @@ ComunicWeb.pages.createAccount = {
|
||||
innerHTML: "Use the following form to create an account and join the network : "
|
||||
});
|
||||
|
||||
//Create the message target
|
||||
var messagesTarget = createElem2({
|
||||
appendTo: formRoot,
|
||||
type: "div"
|
||||
});
|
||||
|
||||
//Input user first name
|
||||
var firstNameInput = createFormGroup({
|
||||
target: formRoot,
|
||||
@ -99,6 +105,59 @@ ComunicWeb.pages.createAccount = {
|
||||
class: "btn btn-primary",
|
||||
innerHTML: "Create the account"
|
||||
});
|
||||
},
|
||||
|
||||
//Make the form lives
|
||||
submitButton.onclick = function(){
|
||||
|
||||
//Empty the message target
|
||||
emptyElem(messagesTarget);
|
||||
|
||||
//Check the first name
|
||||
if(!ComunicWeb.common.formChecker.checkInput(firstNameInput, true))
|
||||
return notify("Please check your first name !", "danger");
|
||||
|
||||
//Check the last name
|
||||
if(!ComunicWeb.common.formChecker.checkInput(lastNameInput, true))
|
||||
return notify("Please check your last name !", "danger");
|
||||
|
||||
//Check the email address
|
||||
if(!ComunicWeb.common.formChecker.checkInput(emailInput, true))
|
||||
return notify("Please check your email address !", "danger");
|
||||
|
||||
//Check the password
|
||||
if(!ComunicWeb.common.formChecker.checkInput(passwordInput, true))
|
||||
return notify("Please check your password !", "danger");
|
||||
|
||||
//Check the confirmation password
|
||||
if(passwordInput.value != confirmPasswordInput.value)
|
||||
return notify("The two passwords are not the same !", "danger");
|
||||
|
||||
//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(
|
||||
"Account creation failed",
|
||||
"An error occured while trying to create your account. It is most likely to be a server error, or the given email address is already associated with an account.",
|
||||
"danger"
|
||||
));
|
||||
return;
|
||||
}
|
||||
}
|
||||
));
|
||||
};
|
||||
},
|
||||
}
|
@ -207,6 +207,9 @@ class Dev {
|
||||
"js/langs/fr.inc.js",
|
||||
|
||||
//Components
|
||||
//Account component
|
||||
"js/components/account/interface.js",
|
||||
|
||||
//Mail caching
|
||||
"js/components/mailCaching.js",
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user