Manager session cookie OK !

This commit is contained in:
manzerbredes 2016-02-24 14:39:47 +01:00
parent ff1832adcf
commit c511010ec4
4 changed files with 29 additions and 11 deletions

View file

@ -7,14 +7,17 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
var profile={};
profile.username=null;
profile.projectname=null;
profile.token=null;
var token={};
token.part_0=null;
token.part_1=null;
/**
* Save profile in cookies
*/
var saveCookieForSession=function(){
$cookies.putObject('profile', 5);
$cookies.putObject('profile', profile);
$cookies.putObject('token.part_0', token.part_0);
$cookies.putObject('token.part_1', token.part_1);
};
@ -23,10 +26,17 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
*/
var isAlreadyLogin=function(){
var profileInCookie=$cookies.getObject('profile');
console.log(profileInCookie);
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
var tokenPart_1InCookie=$cookies.getObject('token.part_0');
if(typeof profileInCookie !== 'undefined'){
if(typeof profileInCookie !== 'undefined'
&& typeof tokenPart_0InCookie !== 'undefined'
&& typeof tokenPart_1InCookie !== 'undefined'
){
angular.extend(profile, profileInCookie);
token.part_0=tokenPart_0InCookie;
token.part_1=tokenPart_1InCookie;
return true;
}
@ -38,6 +48,8 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
*/
var logout=function(){
$cookies.remove('profile');
$cookies.remove('token.part_0');
$cookies.remove('token.part_1');
}
@ -56,7 +68,11 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
if (typeof response.data.token !== 'undefined') {
requestParserResult.status=0;
profile.token=response.data.token;
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();
}
else if(failedToSendRequest){
@ -70,6 +86,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
};
var getToken=function(){
return token.part_0+token.part_1;
}
/**
* Function to connect to OpenStack
@ -104,7 +123,8 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
login: login,
profile: profile,
isAlreadyLogin: isAlreadyLogin,
logout:logout
logout:logout,
getToken:getToken
};