mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-25 05:19:22 +00:00
Login/logout system OK
This commit is contained in:
parent
92413b3667
commit
60cbfd020d
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
|
||||
*/
|
||||
loginSubmit: function(){},
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Logout controller
|
||||
*/
|
||||
logout: {
|
||||
/**
|
||||
* Open logout page and perform logout
|
||||
*/
|
||||
openLogoutPage: function(additionnalData, targetElement){},
|
||||
},
|
||||
|
||||
},
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
|
||||
ComunicWeb.common.network = {
|
||||
|
||||
/**
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
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",
|
||||
},
|
||||
|
||||
/**
|
||||
* Logout page
|
||||
*/
|
||||
logout: {
|
||||
pageTitle: "Logout",
|
||||
methodHandler: "ComunicWeb.pages.logout.openLogoutPage",
|
||||
},
|
||||
|
||||
/**
|
||||
* 404 Page not found
|
||||
*/
|
||||
|
@ -163,8 +163,17 @@ ComunicWeb.user.userLogin = {
|
||||
ComunicWeb.user.loginTokens.setUserTokens(result.tokens, storageType);
|
||||
}
|
||||
|
||||
//Perform next action
|
||||
//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);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user