From 7015e10dd3d70bafd2db76c7b8012e632e2c6848 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 11 Apr 2018 10:52:06 +0200 Subject: [PATCH] Send a request to create an account on the server --- assets/css/pages/createAccount.css | 4 ++ assets/js/common/functionsSchema.js | 14 ++++++ assets/js/common/shorcuts.js | 12 +++++ assets/js/components/account/interface.js | 34 +++++++++++++ assets/js/pages/createAccount.js | 61 ++++++++++++++++++++++- system/config/dev.config.php | 3 ++ 6 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 assets/js/components/account/interface.js diff --git a/assets/css/pages/createAccount.css b/assets/css/pages/createAccount.css index 14475f81..821feaa1 100644 --- a/assets/css/pages/createAccount.css +++ b/assets/css/pages/createAccount.css @@ -21,6 +21,10 @@ text-align: center; } +.create-account-form .callout p { + text-align: justify; +} + .create-account-form .submit-form { text-align: center; } \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index ae5b5b0d..e21f1fe4 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -441,6 +441,20 @@ var ComunicWeb = { */ components: { + /** + * Account component + */ + account: { + + /** + * Interface + */ + interface: { + //TODO : implement + }, + + }, + /** * Menubar */ diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index ecc6015e..fd6ecbe7 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -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) } \ No newline at end of file diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js new file mode 100644 index 00000000..102973cb --- /dev/null +++ b/assets/js/components/account/interface.js @@ -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); + + }, + +} \ No newline at end of file diff --git a/assets/js/pages/createAccount.js b/assets/js/pages/createAccount.js index 48a81433..f1e29cb3 100644 --- a/assets/js/pages/createAccount.js +++ b/assets/js/pages/createAccount.js @@ -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; + } + } + )); + }; + }, } \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index c35c50f9..569fe941 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -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",