diff options
| author | EoleDev <EoleDev@outlook.fr> | 2016-02-17 16:53:58 +0100 |
|---|---|---|
| committer | EoleDev <EoleDev@outlook.fr> | 2016-02-17 16:53:58 +0100 |
| commit | 2b38742bce1691f653dee924c1f030d14053c49e (patch) | |
| tree | bf80308883fe0223146e6cda4d680fb876d43084 /client/js/services/Identity.js | |
| parent | a8b6e051b4a4346ec4b22e07207f8dc766833c9b (diff) | |
| parent | 47e7d7d5402b3096a7554193eec10ff4b8bb2c3b (diff) | |
Merge branch 'develop' into Eole
Diffstat (limited to 'client/js/services/Identity.js')
| -rw-r--r-- | client/js/services/Identity.js | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 4c8919c..d96b3ab 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 @@ -9,7 +9,72 @@ mainApp.factory('Identity',[ '$http', function($http){ profile.projectname=null; profile.token=null; +/* var tokenFragment=9; + + var saveTokenInCookies=function(){ + var i=0; + var currentStart=0; + var currentEnd=parseInt(profile.token.length/tokenFragment); + var facto=currentEnd; + + alert("current ren" + currentEnd); + for(i=0;i<tokenFragment-1;i++){ + + $cookies.put("token-"+i, profile.token.substring(currentStart, currentEnd)); + + + currentStart=currentEnd+1; + currentEnd=currentEnd+facto; + + + } + $cookies.put("token-"+(i+1), profile.token.substring(currentEnd, profile.token.length)); + }; + + var loadTokenInCookies=function(){ + var i=0; + + profile.token=$cookies.get("token-0"); + for(i=1;i<tokenFragment;i++){ + + profile.token=profile.token+$cookies.get("token-"+i) + + + + + } + + + };*/ + + + + var saveCookieForSession=function(){ + $cookies.putObject('profile', 5); + //saveTokenInCookies(); + }; + + + + + + var isAlreadyLogin=function(){ + var profileInCookie=$cookies.getObject('profile'); + console.log(profileInCookie); + + if(typeof profileInCookie !== 'undefined'){ + angular.extend(profile, profileInCookie); + return true; + } + + return false; + } + + var logout=function(){ + $cookies.remove('profile'); + } + /** * * @param {string} response The response to parse @@ -17,6 +82,7 @@ mainApp.factory('Identity',[ '$http', function($http){ * @returns {requestParserResult} Formated data */ var parseLoginAnswer=function(response, failedToSendRequest){ + var requestParserResult={}; requestParserResult.status=1; @@ -24,7 +90,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 +115,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; @@ -67,7 +134,9 @@ mainApp.factory('Identity',[ '$http', function($http){ // Return services objects return { login: login, - profile: profile + profile: profile, + isAlreadyLogin: isAlreadyLogin, + logout:logout }; |
