app factory Users resource function resource return resource api users

 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
app.factory('Users', ['$resource', function($resource) {
return $resource('/api/users/users/:id/:action/?', {id: '@id'}, {
update_password: {
params: {action: 'update_password'},
method: 'POST'
},
update_two_factor_info: {
params: {action: 'update_two_factor_info'},
method: 'PUT'
},
current: {
params: {action: 'current'},
method: 'GET',
isArray: false
},
logout: {
params: {action: 'logout'},
method: 'POST'
},
getOrganizations: {
params: {action: 'organizations'},
method: 'GET',
isArray: true
}
});
}]);
app.service('UserService', ['Users', function(Users) {
this.getCurrent = function() {
if (!this.hasOwnProperty('currentUser')) {
this.currentUser = Users.current();
}
return this.currentUser;
};
this.logout = function(callback) {
return Users.logout(callback);
};
}]);