summaryrefslogtreecommitdiff
path: root/client/js/services/Identity.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/js/services/Identity.js')
-rw-r--r--client/js/services/Identity.js46
1 files changed, 30 insertions, 16 deletions
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
index 0dfba47..2042efd 100644
--- a/client/js/services/Identity.js
+++ b/client/js/services/Identity.js
@@ -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