mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Login form on homepage working
This commit is contained in:
		@@ -22,17 +22,6 @@ ComunicWeb.components.menuBar.notAuthenticated = {
 | 
				
			|||||||
		loginForm.className = "navbar-form navbar-left menubar-loginForm";
 | 
							loginForm.className = "navbar-form navbar-left menubar-loginForm";
 | 
				
			||||||
		loginForm.setAttribute("role", "login");
 | 
							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
 | 
							//Add email address formGroup
 | 
				
			||||||
		var emailFormGroup = createElem("div", loginForm);
 | 
							var emailFormGroup = createElem("div", loginForm);
 | 
				
			||||||
		emailFormGroup.className = "form-group";
 | 
							emailFormGroup.className = "form-group";
 | 
				
			||||||
@@ -63,5 +52,41 @@ ComunicWeb.components.menuBar.notAuthenticated = {
 | 
				
			|||||||
		submitInput.className = "form-control";
 | 
							submitInput.className = "form-control";
 | 
				
			||||||
		submitInput.value = "Login";
 | 
							submitInput.value = "Login";
 | 
				
			||||||
		submitInput.type = "submit";
 | 
							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 
 | 
						 * @returns {Boolean} False if it fails 
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	openLoginPage: function(additionnalData, targetElement){
 | 
						openLoginPage: function(additionnalData, targetElement){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Prevent errors
 | 
				
			||||||
 | 
							if(!additionnalData)
 | 
				
			||||||
 | 
								additionnalData = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//First, check if user is already logged in or not
 | 
							//First, check if user is already logged in or not
 | 
				
			||||||
		if(ComunicWeb.user.userLogin.getUserLoginState() === true){
 | 
							if(ComunicWeb.user.userLogin.getUserLoginState() === true){
 | 
				
			||||||
			//Log message
 | 
								//Log message
 | 
				
			||||||
@@ -55,12 +60,15 @@ ComunicWeb.pages.login = {
 | 
				
			|||||||
			//loginButton.onclick = ComunicWeb.pages.login.loginSubmit;
 | 
								//loginButton.onclick = ComunicWeb.pages.login.loginSubmit;
 | 
				
			||||||
			loginBody.onsubmit = 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
 | 
								//Check if we have to display a login failed message
 | 
				
			||||||
			if(additionnalData.loginFailedMessage)
 | 
								if(additionnalData.loginFailedMessage)
 | 
				
			||||||
				ComunicWeb.pages.login.displayLoginError();
 | 
									ComunicWeb.pages.login.displayLoginError();
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Apply template
 | 
							//Apply template
 | 
				
			||||||
@@ -104,9 +112,6 @@ ComunicWeb.pages.login = {
 | 
				
			|||||||
			//First, remove overlay
 | 
								//First, remove overlay
 | 
				
			||||||
			screenOverlay.remove();
 | 
								screenOverlay.remove();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Save email address
 | 
					 | 
				
			||||||
			ComunicWeb.components.mailCaching.set(usermail);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Check if login failed
 | 
								//Check if login failed
 | 
				
			||||||
			if(!loginResult){
 | 
								if(!loginResult){
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -161,6 +161,9 @@ ComunicWeb.user.userLogin = {
 | 
				
			|||||||
                    storageType = "session";
 | 
					                    storageType = "session";
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
 | 
					                ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //Save email address
 | 
				
			||||||
 | 
					                ComunicWeb.components.mailCaching.set(usermail);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Perform next action if login failed
 | 
					            //Perform next action if login failed
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user