Simplify Identity

This commit is contained in:
manzerbredes 2016-02-24 15:02:14 +01:00
parent 7676509fcd
commit 211ebb0e43
3 changed files with 37 additions and 18 deletions
client/js
controllers
services

View file

@ -13,13 +13,18 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s
if(!Identity.isAlreadyLogin()){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
}
// Manager logout event
$scope.$on('logoutEvent', function(){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
});
// Hide loading button and message alert
$('#loadingLoginButton').hide();
$('#failedToLoginAlert').hide();
// Defined function for login
$scope.loginAction=function(){
// Begin login state for template

View file

@ -10,7 +10,7 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($
{
// Give profile to model
$scope.profile=Identity.profile;
$scope.profile=Identity.getProfile();
// Function to logout
$scope.logout=function(){

View file

@ -7,10 +7,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
var profile={};
profile.username=null;
profile.projectname=null;
var token={};
token.part_0=null;
token.part_1=null;
var token=null;
/**
* Save profile in cookies
*/
@ -27,7 +26,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
var isAlreadyLogin=function(){
var profileInCookie=$cookies.getObject('profile');
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
var tokenPart_1InCookie=$cookies.getObject('token.part_0');
var tokenPart_1InCookie=$cookies.getObject('token.part_1');
if(typeof profileInCookie !== 'undefined'
@ -35,14 +34,29 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
&& typeof tokenPart_1InCookie !== 'undefined'
){
angular.extend(profile, profileInCookie);
token.part_0=tokenPart_0InCookie;
token.part_1=tokenPart_1InCookie;
token=tokenPart_0InCookie+tokenPart_1InCookie;
return true;
}
return false;
}
/*
* Get the profile
*/
var getProfile=function(){
return profile;
}
/*
* Get the token
*/
var getToken=function(){
return token;
}
/*
* Destroy profile cookies
*/
@ -67,13 +81,18 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
requestParserResult.failReason=null;
if (typeof response.data.token !== 'undefined') {
// Set status code
requestParserResult.status=0;
// Find the middle of the token to split it
var middle=parseInt(response.data.token.length/2);
token.part_0=response.data.token.substring(0, middle);
token.part_1=response.data.token.substring(middle, response.data.token.length);
saveCookieForSession();
// Save profile
$cookies.putObject('profile', profile);
// Save first part of token
$cookies.putObject('token.part_0', response.data.token.substring(0, middle));
// Save second part of token
$cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length));
}
else if(failedToSendRequest){
requestParserResult.failReason="Failed to send request";
@ -84,11 +103,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
return requestParserResult;
};
var getToken=function(){
return token.part_0+token.part_1;
}
/**
* Function to connect to OpenStack
@ -121,7 +135,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
// Return services objects
return {
login: login,
profile: profile,
getProfile: getProfile,
isAlreadyLogin: isAlreadyLogin,
logout:logout,
getToken:getToken