mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Login/logout system OK
This commit is contained in:
		
							
								
								
									
										3
									
								
								README.md.bak
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								README.md.bak
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					# WEB-WebComunicApp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					WebComunic RestClient
 | 
				
			||||||
@@ -335,7 +335,17 @@ var ComunicWeb = {
 | 
				
			|||||||
             * Perform user login
 | 
					             * Perform user login
 | 
				
			||||||
             */
 | 
					             */
 | 
				
			||||||
            loginSubmit: function(){},
 | 
					            loginSubmit: function(){},
 | 
				
			||||||
        }
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * Logout controller
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        logout: {
 | 
				
			||||||
 | 
					            /**
 | 
				
			||||||
 | 
					             * Open logout page and perform logout
 | 
				
			||||||
 | 
					             */
 | 
				
			||||||
 | 
					            openLogoutPage: function(additionnalData, targetElement){},
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -4,7 +4,6 @@
 | 
				
			|||||||
 * @author Pierre HUBERT
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
ComunicWeb.common.network = {
 | 
					ComunicWeb.common.network = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -92,13 +92,18 @@ ComunicWeb.common.page = {
 | 
				
			|||||||
        //Extract the first part of the URL
 | 
					        //Extract the first part of the URL
 | 
				
			||||||
        var firstPartURI = pageURI.toString();
 | 
					        var firstPartURI = pageURI.toString();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        //Check if there are hashtag for the URL
 | 
				
			||||||
 | 
					        if(firstPartURI.indexOf("#") != -1){
 | 
				
			||||||
 | 
					            firstPartURI = firstPartURI.split("#")[0];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Check if pageURI is empty
 | 
					        //Check if pageURI is empty
 | 
				
			||||||
        if(firstPartURI == ""){
 | 
					        if(firstPartURI == ""){
 | 
				
			||||||
            firstPartURI = "home";
 | 
					            firstPartURI = "home";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Check if there is also subfolders
 | 
					        //Check if there is also subfolders
 | 
				
			||||||
        if(firstPartURI.indexOf("/") != "/"){
 | 
					        if(firstPartURI.indexOf("/") != -1){
 | 
				
			||||||
            firstPartURI = firstPartURI.split("/")[0];
 | 
					            firstPartURI = firstPartURI.split("/")[0];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,7 @@ ComunicWeb.common.url = {
 | 
				
			|||||||
        var newURL = ComunicWeb.__config.siteURL + newURI;
 | 
					        var newURL = ComunicWeb.__config.siteURL + newURI;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        //Apply it
 | 
					        //Apply it
 | 
				
			||||||
		window.history.pushState("object or string", newTitle, newURI);
 | 
							window.history.pushState("object or string", newTitle, newURL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Everything is OK 
 | 
					        //Everything is OK 
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,9 +18,25 @@ ComunicWeb.pages.home.home = {
 | 
				
			|||||||
        //Dev feature : Show result
 | 
					        //Dev feature : Show result
 | 
				
			||||||
        if(userLoggedIn){
 | 
					        if(userLoggedIn){
 | 
				
			||||||
            targetElement.appendChild(ComunicWeb.common.messages.createCalloutElem("", "User logged in !", "info"));
 | 
					            targetElement.appendChild(ComunicWeb.common.messages.createCalloutElem("", "User logged in !", "info"));
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            //Create logout button
 | 
				
			||||||
 | 
					            var loginButton = document.createElement("button");
 | 
				
			||||||
 | 
					            loginButton.onclick = (function(){
 | 
				
			||||||
 | 
					                ComunicWeb.common.page.openPage("logout");
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            loginButton.innerHTML="Logout";
 | 
				
			||||||
 | 
					            targetElement.appendChild(loginButton);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else{
 | 
					        else{
 | 
				
			||||||
            targetElement.appendChild(ComunicWeb.common.messages.createCalloutElem("", "User not logged in !", "warning"));
 | 
					            targetElement.appendChild(ComunicWeb.common.messages.createCalloutElem("", "User not logged in !", "warning"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //Create login button
 | 
				
			||||||
 | 
					            var loginButton = document.createElement("button");
 | 
				
			||||||
 | 
					            loginButton.onclick = (function(){
 | 
				
			||||||
 | 
					                ComunicWeb.common.page.openPage("login");
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            loginButton.innerHTML="Login";
 | 
				
			||||||
 | 
					            targetElement.appendChild(loginButton);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Everything seems to be OK
 | 
					        //Everything seems to be OK
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,9 @@ ComunicWeb.pages.login = {
 | 
				
			|||||||
            //Get login button
 | 
					            //Get login button
 | 
				
			||||||
            var loginButton = loginBody.getElementsByClassName("btn-login")[0];
 | 
					            var loginButton = loginBody.getElementsByClassName("btn-login")[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            loginButton.onclick=ComunicWeb.pages.login.loginSubmit;
 | 
					            //Make the login action accessible
 | 
				
			||||||
 | 
					            //loginButton.onclick = ComunicWeb.pages.login.loginSubmit;
 | 
				
			||||||
 | 
					            loginBody.onsubmit = ComunicWeb.pages.login.loginSubmit;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Apply template
 | 
					        //Apply template
 | 
				
			||||||
@@ -62,14 +64,14 @@ ComunicWeb.pages.login = {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    loginSubmit: function(){
 | 
					    loginSubmit: function(){
 | 
				
			||||||
        //Get inputs
 | 
					        //Get inputs
 | 
				
			||||||
        var usermail = document.getElementById("usermail"); //Usermail
 | 
					        var usermailInput = document.getElementById("usermail"); //Usermail
 | 
				
			||||||
        var userpassword = document.getElementById("userpassword"); //Password
 | 
					        var userpasswordInput = document.getElementById("userpassword"); //Password
 | 
				
			||||||
        var rememberLogin = document.getElementById("rememberLogin"); //Remember login
 | 
					        var rememberLoginInput = document.getElementById("rememberLogin"); //Remember login
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Check inputs
 | 
					        //Check inputs
 | 
				
			||||||
        if(!(
 | 
					        if(!(
 | 
				
			||||||
            ComunicWeb.common.formChecker.checkInput(usermail, true) && //Check usermail input
 | 
					            ComunicWeb.common.formChecker.checkInput(usermailInput, true) && //Check usermail input
 | 
				
			||||||
            ComunicWeb.common.formChecker.checkInput(userpassword, true) //Check password input
 | 
					            ComunicWeb.common.formChecker.checkInput(userpasswordInput, true) //Check password input
 | 
				
			||||||
        )){
 | 
					        )){
 | 
				
			||||||
           //Error notification
 | 
					           //Error notification
 | 
				
			||||||
           ComunicWeb.common.notificationSystem.showNotification("Please check what you've typed !", "error");
 | 
					           ComunicWeb.common.notificationSystem.showNotification("Please check what you've typed !", "error");
 | 
				
			||||||
@@ -78,7 +80,38 @@ ComunicWeb.pages.login = {
 | 
				
			|||||||
           return false;
 | 
					           return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
       
 | 
					       
 | 
				
			||||||
 | 
					        //Enable overlay (use .remove() to remove)
 | 
				
			||||||
 | 
					        var screenOverlay = ComunicWeb.common.page.showTransparentWaitSplashScreen();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        var overlay = ComunicWeb.common.page.showTransparentWaitSplashScreen();
 | 
					        //Retrieve values
 | 
				
			||||||
 | 
					        var usermail = usermailInput.value; 
 | 
				
			||||||
 | 
					        var userpassword = userpasswordInput.value;
 | 
				
			||||||
 | 
					        var permanentLogin = rememberLoginInput.checked;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //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){
 | 
				
			||||||
 | 
					                //Create error modal
 | 
				
			||||||
 | 
					                errorMessageElem = ComunicWeb.common.messages.createCalloutElem("Login failed", "Please check your usermail and password", "danger");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //Apply error modal
 | 
				
			||||||
 | 
					                document.getElementById('loginMessagesTarget').innerHTML = "";
 | 
				
			||||||
 | 
					                document.getElementById('loginMessagesTarget').appendChild(errorMessageElem);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //Return false
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					           }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					           //Open home page
 | 
				
			||||||
 | 
					           ComunicWeb.common.page.openPage("home");
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Try to login user
 | 
				
			||||||
 | 
					        ComunicWeb.user.userLogin.loginUser(usermail, userpassword, permanentLogin, afterTryLogin);
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
							
								
								
									
										30
									
								
								assets/js/pages/logout.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								assets/js/pages/logout.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Logout page main controller
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ComunicWeb.pages.logout = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Open logout page and perform logout
 | 
				
			||||||
 | 
					     * 
 | 
				
			||||||
 | 
					     * @param {Object} additionnalData Additionnal data passed in the method
 | 
				
			||||||
 | 
					     * @param {element} targetElement Where the template will be applied
 | 
				
			||||||
 | 
					     * @returns {Boolean} False if it fails 
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    openLogoutPage: function(additionnalData, targetElement){
 | 
				
			||||||
 | 
					        //Enable screen overlay
 | 
				
			||||||
 | 
					        var screenOverlay = ComunicWeb.common.page.showTransparentWaitSplashScreen();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Perform logout
 | 
				
			||||||
 | 
					        ComunicWeb.user.userLogin.logoutUser();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Show a success notification
 | 
				
			||||||
 | 
					        ComunicWeb.common.notificationSystem.showNotification("Good bye, you were sucessfully logouted !", "sucess", 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Open login page
 | 
				
			||||||
 | 
					        ComunicWeb.common.page.openPage("login");
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -21,6 +21,14 @@ ComunicWeb.pagesList = {
 | 
				
			|||||||
        methodHandler: "ComunicWeb.pages.login.openLoginPage",
 | 
					        methodHandler: "ComunicWeb.pages.login.openLoginPage",
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Logout page
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    logout: {
 | 
				
			||||||
 | 
					        pageTitle: "Logout",
 | 
				
			||||||
 | 
					        methodHandler: "ComunicWeb.pages.logout.openLogoutPage",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 404 Page not found
 | 
					     * 404 Page not found
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -163,8 +163,17 @@ ComunicWeb.user.userLogin = {
 | 
				
			|||||||
                ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
 | 
					                ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Perform next action
 | 
					            //Perform next action if login failed
 | 
				
			||||||
 | 
					            if(!loginstate) {
 | 
				
			||||||
                afterLogin(loginstate);
 | 
					                afterLogin(loginstate);
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //Else refresh login state to get user ID
 | 
				
			||||||
 | 
					            ComunicWeb.user.userLogin.refreshLoginState(function(){
 | 
				
			||||||
 | 
					                //And then we'll be able to perform next action
 | 
				
			||||||
 | 
					                afterLogin(true);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,10 @@
 | 
				
			|||||||
    <!-- Login message -->
 | 
					    <!-- Login message -->
 | 
				
			||||||
    <p class="login-box-msg">Login to your Comunic account.</p>
 | 
					    <p class="login-box-msg">Login to your Comunic account.</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div id="loginForm">
 | 
					    <!-- Optionnal messages target -->
 | 
				
			||||||
 | 
					    <div id="loginMessagesTarget"></div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <form id="loginForm" action="javascript:(function(){})();">
 | 
				
			||||||
      <div class="form-group has-feedback">
 | 
					      <div class="form-group has-feedback">
 | 
				
			||||||
        <input type="email" class="form-control" placeholder="Email" id="usermail" />
 | 
					        <input type="email" class="form-control" placeholder="Email" id="usermail" />
 | 
				
			||||||
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
 | 
					        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
 | 
				
			||||||
@@ -31,7 +34,7 @@
 | 
				
			|||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <!-- /.col -->
 | 
					        <!-- /.col -->
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </form>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <!-- /.login-box-body -->
 | 
					  <!-- /.login-box-body -->
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,6 +55,7 @@ $config['JSfiles'] = array(
 | 
				
			|||||||
    //Pages scripts
 | 
					    //Pages scripts
 | 
				
			||||||
    "%PATH_ASSETS%js/pages/home/home.js",
 | 
					    "%PATH_ASSETS%js/pages/home/home.js",
 | 
				
			||||||
    "%PATH_ASSETS%js/pages/login.js",
 | 
					    "%PATH_ASSETS%js/pages/login.js",
 | 
				
			||||||
 | 
					    "%PATH_ASSETS%js/pages/logout.js",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Init script
 | 
					    //Init script
 | 
				
			||||||
    "%PATH_ASSETS%js/init.js",
 | 
					    "%PATH_ASSETS%js/init.js",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user