mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-02-16 19:02:40 +00:00
Login form on homepage working
This commit is contained in:
parent
5c5a65cdff
commit
7dd286d6d6
@ -22,17 +22,6 @@ ComunicWeb.components.menuBar.notAuthenticated = {
|
||||
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,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Add email address formGroup
|
||||
var emailFormGroup = createElem("div", loginForm);
|
||||
emailFormGroup.className = "form-group";
|
||||
@ -63,5 +52,41 @@ ComunicWeb.components.menuBar.notAuthenticated = {
|
||||
submitInput.className = "form-control";
|
||||
submitInput.value = "Login";
|
||||
submitInput.type = "submit";
|
||||
|
||||
//Add submit form behaviour
|
||||
loginForm.onsubmit = function(){
|
||||
//Enable screen overlay (use .remove() to remove)
|
||||
var screenOverlay = ComunicWeb.common.page.showTransparentWaitSplashScreen();
|
||||
|
||||
//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 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){
|
||||
|
||||
|
@ -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…
x
Reference in New Issue
Block a user