Login/logout system OK

This commit is contained in:
Pierre 2017-03-01 15:37:55 +01:00
parent 92413b3667
commit 60cbfd020d
13 changed files with 134 additions and 17 deletions

3
README.md.bak Normal file
View File

@ -0,0 +1,3 @@
# WEB-WebComunicApp
WebComunic RestClient

View File

@ -335,7 +335,17 @@ var ComunicWeb = {
* Perform user login
*/
loginSubmit: function(){},
}
},
/**
* Logout controller
*/
logout: {
/**
* Open logout page and perform logout
*/
openLogoutPage: function(additionnalData, targetElement){},
},
},
}

View File

@ -4,7 +4,6 @@
* @author Pierre HUBERT
*/
ComunicWeb.common.network = {
/**

View File

@ -92,13 +92,18 @@ ComunicWeb.common.page = {
//Extract the first part of the URL
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
if(firstPartURI == ""){
firstPartURI = "home";
}
//Check if there is also subfolders
if(firstPartURI.indexOf("/") != "/"){
if(firstPartURI.indexOf("/") != -1){
firstPartURI = firstPartURI.split("/")[0];
}

View File

@ -34,7 +34,7 @@ ComunicWeb.common.url = {
var newURL = ComunicWeb.__config.siteURL + newURI;
//Apply it
window.history.pushState("object or string", newTitle, newURI);
window.history.pushState("object or string", newTitle, newURL);
//Everything is OK
return true;

View File

@ -18,9 +18,25 @@ ComunicWeb.pages.home.home = {
//Dev feature : Show result
if(userLoggedIn){
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{
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

View File

@ -48,7 +48,9 @@ ComunicWeb.pages.login = {
//Get login button
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
@ -62,14 +64,14 @@ ComunicWeb.pages.login = {
*/
loginSubmit: function(){
//Get inputs
var usermail = document.getElementById("usermail"); //Usermail
var userpassword = document.getElementById("userpassword"); //Password
var rememberLogin = document.getElementById("rememberLogin"); //Remember login
var usermailInput = document.getElementById("usermail"); //Usermail
var userpasswordInput = document.getElementById("userpassword"); //Password
var rememberLoginInput = document.getElementById("rememberLogin"); //Remember login
//Check inputs
if(!(
ComunicWeb.common.formChecker.checkInput(usermail, true) && //Check usermail input
ComunicWeb.common.formChecker.checkInput(userpassword, true) //Check password input
ComunicWeb.common.formChecker.checkInput(usermailInput, true) && //Check usermail input
ComunicWeb.common.formChecker.checkInput(userpasswordInput, true) //Check password input
)){
//Error notification
ComunicWeb.common.notificationSystem.showNotification("Please check what you've typed !", "error");
@ -78,7 +80,38 @@ ComunicWeb.pages.login = {
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
View 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");
},
};

View File

@ -21,6 +21,14 @@ ComunicWeb.pagesList = {
methodHandler: "ComunicWeb.pages.login.openLoginPage",
},
/**
* Logout page
*/
logout: {
pageTitle: "Logout",
methodHandler: "ComunicWeb.pages.logout.openLogoutPage",
},
/**
* 404 Page not found
*/

View File

@ -163,8 +163,17 @@ ComunicWeb.user.userLogin = {
ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
}
//Perform next action
afterLogin(loginstate);
//Perform next action if login failed
if(!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);
});
};

View File

@ -8,7 +8,10 @@
<!-- Login message -->
<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">
<input type="email" class="form-control" placeholder="Email" id="usermail" />
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
@ -31,7 +34,7 @@
</div>
<!-- /.col -->
</div>
</div>
</form>
</div>
<!-- /.login-box-body -->
</div>

View File

@ -55,6 +55,7 @@ $config['JSfiles'] = array(
//Pages scripts
"%PATH_ASSETS%js/pages/home/home.js",
"%PATH_ASSETS%js/pages/login.js",
"%PATH_ASSETS%js/pages/logout.js",
//Init script
"%PATH_ASSETS%js/init.js",