summaryrefslogtreecommitdiff
path: root/client/js/services/Identity.js
diff options
context:
space:
mode:
authorYoggzo <yogg@epsina.com>2016-02-24 13:23:47 +0100
committerYoggzo <yogg@epsina.com>2016-02-24 13:23:47 +0100
commitfafb5eeaa4676823680c828ac57adf2e855b7afd (patch)
tree58c914ba9b277252daf53c27e878f262cb4579ad /client/js/services/Identity.js
parent16e0328884f318d97ac991ee8e70f43ee1c14b38 (diff)
parentd2f5ae5c83ef5bc41cf430ace79769459b4acbf8 (diff)
Merge branch 'develop' into Evan
Diffstat (limited to 'client/js/services/Identity.js')
-rw-r--r--client/js/services/Identity.js45
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
};