mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 12:09:21 +00:00
Login form on homepage working
This commit is contained in:
parent
5c5a65cdff
commit
7dd286d6d6
@ -5,63 +5,88 @@
|
||||
*/
|
||||
|
||||
ComunicWeb.components.menuBar.notAuthenticated = {
|
||||
/**
|
||||
* Add not-authenticated user specific elements
|
||||
*
|
||||
* @param {HTMLElement} container The container element of the Menubar
|
||||
*/
|
||||
addElements: function(container){
|
||||
/**
|
||||
* Add not-authenticated user specific elements
|
||||
*
|
||||
* @param {HTMLElement} container The container element of the Menubar
|
||||
*/
|
||||
addElements: function(container){
|
||||
|
||||
//Create an auto-collapsed element
|
||||
var navbarCollapse = createElem("div", container);
|
||||
navbarCollapse.id = "navbar-collapse";
|
||||
navbarCollapse.className = "navbar-collapse pull-right collapse";
|
||||
//Create an auto-collapsed element
|
||||
var navbarCollapse = createElem("div", container);
|
||||
navbarCollapse.id = "navbar-collapse";
|
||||
navbarCollapse.className = "navbar-collapse pull-right collapse";
|
||||
|
||||
//Create login form
|
||||
var loginForm = createElem("form", navbarCollapse);
|
||||
loginForm.className = "navbar-form navbar-left menubar-loginForm";
|
||||
loginForm.setAttribute("role", "login");
|
||||
//Create login form
|
||||
var loginForm = createElem("form", navbarCollapse);
|
||||
loginForm.className = "navbar-form navbar-left menubar-loginForm";
|
||||
loginForm.setAttribute("role", "login");
|
||||
|
||||
loginForm.onsubmit = function(){
|
||||
//Try to login user; in case of failure redirect to login page
|
||||
//TODO : implement
|
||||
//In case of error
|
||||
ComunicWeb.common.page.openPage("login", {
|
||||
loginFailedMessage: true,
|
||||
});
|
||||
//Add email address formGroup
|
||||
var emailFormGroup = createElem("div", loginForm);
|
||||
emailFormGroup.className = "form-group";
|
||||
|
||||
return false;
|
||||
}
|
||||
//Add email input
|
||||
var emailInput = createElem("input", emailFormGroup);
|
||||
emailInput.className = "form-control";
|
||||
emailInput.placeholder = "Email address";
|
||||
emailInput.type = "email";
|
||||
emailInput.value = ComunicWeb.components.mailCaching.get();
|
||||
|
||||
//Add email address formGroup
|
||||
var emailFormGroup = createElem("div", loginForm);
|
||||
emailFormGroup.className = "form-group";
|
||||
//Add password formGroup
|
||||
var passwordFormGroup = createElem("div", loginForm);
|
||||
passwordFormGroup.className = "form-group";
|
||||
|
||||
//Add email input
|
||||
var emailInput = createElem("input", emailFormGroup);
|
||||
emailInput.className = "form-control";
|
||||
emailInput.placeholder = "Email address";
|
||||
emailInput.type = "email";
|
||||
emailInput.value = ComunicWeb.components.mailCaching.get();
|
||||
//Add password input
|
||||
var passwordInput = createElem("input", passwordFormGroup);
|
||||
passwordInput.className = "form-control";
|
||||
passwordInput.placeholder = "Password";
|
||||
passwordInput.type = "password";
|
||||
|
||||
//Add password formGroup
|
||||
var passwordFormGroup = createElem("div", loginForm);
|
||||
passwordFormGroup.className = "form-group";
|
||||
//Add submit button formGroup
|
||||
var submitFromGroup = createElem("div", loginForm);
|
||||
submitFromGroup.className = "form-group";
|
||||
|
||||
//Add password input
|
||||
var passwordInput = createElem("input", passwordFormGroup);
|
||||
passwordInput.className = "form-control";
|
||||
passwordInput.placeholder = "Password";
|
||||
passwordInput.type = "password";
|
||||
//Add submit input
|
||||
var submitInput = createElem("input", submitFromGroup);
|
||||
submitInput.className = "form-control";
|
||||
submitInput.value = "Login";
|
||||
submitInput.type = "submit";
|
||||
|
||||
//Add submit button formGroup
|
||||
var submitFromGroup = createElem("div", loginForm);
|
||||
submitFromGroup.className = "form-group";
|
||||
//Add submit form behaviour
|
||||
loginForm.onsubmit = function(){
|
||||
//Enable screen overlay (use .remove() to remove)
|
||||
var screenOverlay = ComunicWeb.common.page.showTransparentWaitSplashScreen();
|
||||
|
||||
//Add submit input
|
||||
var submitInput = createElem("input", submitFromGroup);
|
||||
submitInput.className = "form-control";
|
||||
submitInput.value = "Login";
|
||||
submitInput.type = "submit";
|
||||
}
|
||||
//Try to login user; in case of failure redirect to login page
|
||||
//What to do once user is logged in (or not)
|
||||
var afterTryLogin = function(loginResult){
|
||||
|
||||
//First, remove overlay
|
||||
screenOverlay.remove();
|
||||
|
||||
//Check if login failed
|
||||
if(!loginResult){
|
||||
|
||||
//Redirect to login page
|
||||
ComunicWeb.common.page.openPage("login", {
|
||||
loginFailedMessage: true,
|
||||
emailInput: emailInput.value,
|
||||
});
|
||||
|
||||
//Return false
|
||||
return false;
|
||||
}
|
||||
|
||||
//Open home page
|
||||
ComunicWeb.common.page.openPage("home");
|
||||
};
|
||||
|
||||
//Try to login user
|
||||
ComunicWeb.user.userLogin.loginUser(emailInput.value, passwordInput.value, false, afterTryLogin);
|
||||
|
||||
//Block form
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,11 @@ ComunicWeb.pages.login = {
|
||||
* @returns {Boolean} False if it fails
|
||||
*/
|
||||
openLoginPage: function(additionnalData, targetElement){
|
||||
|
||||
//Prevent errors
|
||||
if(!additionnalData)
|
||||
additionnalData = {};
|
||||
|
||||
//First, check if user is already logged in or not
|
||||
if(ComunicWeb.user.userLogin.getUserLoginState() === true){
|
||||
//Log message
|
||||
@ -55,12 +60,15 @@ ComunicWeb.pages.login = {
|
||||
//loginButton.onclick = ComunicWeb.pages.login.loginSubmit;
|
||||
loginBody.onsubmit = ComunicWeb.pages.login.loginSubmit;
|
||||
|
||||
//Check if additionnal data were specified
|
||||
if(additionnalData){
|
||||
//Check if we have to display a login failed message
|
||||
if(additionnalData.loginFailedMessage)
|
||||
ComunicWeb.pages.login.displayLoginError();
|
||||
}
|
||||
|
||||
//Check now additional parametres changes
|
||||
//Check if a specific email address was specified
|
||||
if(additionnalData.emailInput)
|
||||
byId("usermail").value = additionnalData.emailInput;
|
||||
|
||||
//Check if we have to display a login failed message
|
||||
if(additionnalData.loginFailedMessage)
|
||||
ComunicWeb.pages.login.displayLoginError();
|
||||
};
|
||||
|
||||
//Apply template
|
||||
@ -104,9 +112,6 @@ ComunicWeb.pages.login = {
|
||||
//First, remove overlay
|
||||
screenOverlay.remove();
|
||||
|
||||
//Save email address
|
||||
ComunicWeb.components.mailCaching.set(usermail);
|
||||
|
||||
//Check if login failed
|
||||
if(!loginResult){
|
||||
|
||||
@ -117,8 +122,8 @@ ComunicWeb.pages.login = {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Open home page
|
||||
ComunicWeb.common.page.openPage("home");
|
||||
//Open home page
|
||||
ComunicWeb.common.page.openPage("home");
|
||||
};
|
||||
|
||||
//Try to login user
|
||||
|
@ -161,6 +161,9 @@ ComunicWeb.user.userLogin = {
|
||||
storageType = "session";
|
||||
}
|
||||
ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
|
||||
|
||||
//Save email address
|
||||
ComunicWeb.components.mailCaching.set(usermail);
|
||||
}
|
||||
|
||||
//Perform next action if login failed
|
||||
|
Loading…
Reference in New Issue
Block a user