-
Notifications
You must be signed in to change notification settings - Fork 0
/
cr-user.js
71 lines (63 loc) · 2.03 KB
/
cr-user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
angular.module('cr.user', [])
.factory('crUser', ['$crUser', '$rootScope', function($crUser, $rootScope) {
if($crUser.getAuthSession()){
$rootScope.$emit("$crUserResumeSession", {identity: $crUser.getAuthSession()['cr-user']});
}
return {
setCredentials: function(credentials) {
if($crUser.getAuthHandler()) {
$crUser.getAuthHandler().setSign(credentials);
}
},
login: function(userData, authCredentials) {
$crUser.getAuthSession()['cr-user'] = userData;
if(authCredentials && $crUser.getAuthHandler()) {
$crUser.getAuthHandler().setSign(authCredentials);
}
$rootScope.$emit("$crUserPostLogin", {});
// console.log("my storage in", $crUser._config.authSession);
},
logout: function(){
$crUser.voidSession();
$rootScope.$emit("$crUserPostLogout", {});
},
getIdentity: function() {
return $crUser.getAuthSession()['cr-user'];
},
setParameter: function(name, value){
$crUser.getAuthSession()['cr-user'][name] = value;
},
getParameter: function(name){
return $crUser.getAuthSession()['cr-user'][name];
}
};
}])
.provider('$crUser', function() {
var _config = {
authHandler: null,
authSession: null
};
this.setAuthHandler = function (authHandler) {
_config.authHandler = authHandler;
};
this.getAuthHandler = function() {
return _config.authHandler;
};
this.setAuthSession = function (authSession) {
_config.authSession = authSession;
};
this.getAuthSession = function() {
return _config.authSession;
};
this.voidSession = function() {
if(_config.authSession) {
delete _config.authSession['cr-user'];
}
if(_config.authHandler) {
_config.authHandler.voidSign();
}
};
this.$get = function() {
return this;
};
});