diff options
Diffstat (limited to 'client/js/services/Identity.js')
| -rw-r--r-- | client/js/services/Identity.js | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 4c8919c..8ee664c 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -1,5 +1,5 @@ -mainApp.factory('Identity',[ '$http', function($http){ +mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ /* Create profile structure to store informations * about current session @@ -11,12 +11,44 @@ mainApp.factory('Identity',[ '$http', function($http){ /** + * Save profile in cookies + */ + var saveCookieForSession=function(){ + $cookies.putObject('profile', 5); + }; + + + /* + * @returns {boolean} Return true if a cookie is found (and load it in profile) false else + */ + var isAlreadyLogin=function(){ + var profileInCookie=$cookies.getObject('profile'); + console.log(profileInCookie); + + if(typeof profileInCookie !== 'undefined'){ + angular.extend(profile, profileInCookie); + return true; + } + + return false; + } + + /* + * Destroy profile cookies + */ + var logout=function(){ + $cookies.remove('profile'); + } + + + /** * * @param {string} response The response to parse * @param {boolean} to check if the request is send or not * @returns {requestParserResult} Formated data */ var parseLoginAnswer=function(response, failedToSendRequest){ + var requestParserResult={}; requestParserResult.status=1; @@ -24,7 +56,8 @@ mainApp.factory('Identity',[ '$http', function($http){ if (typeof response.data.token !== 'undefined') { requestParserResult.status=0; - profile.token=response.data.token; + profile.token=response.data.token; + saveCookieForSession(); } else if(failedToSendRequest){ requestParserResult.failReason="Failed to send request"; @@ -48,7 +81,7 @@ mainApp.factory('Identity',[ '$http', function($http){ * @param {function} function to call when data is avalaible */ var login=function(username, password,projectname, callback){ - + // Set profile information (early) profile.username=username; profile.projectname=projectname; @@ -64,10 +97,14 @@ mainApp.factory('Identity',[ '$http', function($http){ }); }; + + // Return services objects return { login: login, - profile: profile + profile: profile, + isAlreadyLogin: isAlreadyLogin, + logout:logout }; |
