Browse Source

load permissions fix

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
5a1f794a08
2 changed files with 16 additions and 10 deletions
  1. 5
    1
      src/luticateauth.js
  2. 11
    9
      src/users.js

+ 5
- 1
src/luticateauth.js View File

3
  */
3
  */
4
 
4
 
5
 (function() {
5
 (function() {
6
-    angular.module("luticateAuth", []);
6
+    angular.module("luticateAuth", []).run(['luticateAuthUsers',
7
+        function(luticateAuthUsers)
8
+    {
9
+        luticateAuthUsers.loadPermissions(null);
10
+    }]);
7
 })();
11
 })();

+ 11
- 9
src/users.js View File

16
                     luticateRequest.post("/api/luticate/users/login", data, null, promise)
16
                     luticateRequest.post("/api/luticate/users/login", data, null, promise)
17
                         .then(function(user)
17
                         .then(function(user)
18
                         {
18
                         {
19
-                            luticateAuthUsers.loadPermissions(user, promise)
19
+                            luticateAuthCache.setUser(user);
20
+                            luticateAuthUsers.loadPermissions(promise)
20
                                 .then(function(permissions)
21
                                 .then(function(permissions)
21
                                 {
22
                                 {
22
-                                    luticateAuthCache.setUser(user);
23
                                     defer.resolve(user);
23
                                     defer.resolve(user);
24
                                 }, function(error)
24
                                 }, function(error)
25
                                 {
25
                                 {
40
                     luticateAuthPermissions.getAllEffectiveMe(promise)
40
                     luticateAuthPermissions.getAllEffectiveMe(promise)
41
                         .then(function(permissions)
41
                         .then(function(permissions)
42
                         {
42
                         {
43
-                            luticateAuthCache.setEffectivePermissions(permissions);
43
+                            var perms = {};
44
+                            for (var i = 0; i < permissions.length; ++i) {
45
+                                var p = permissions[i];
46
+                                perms[p.Name] = p.Value;
47
+                            }
48
+                            luticateAuthCache.setEffectivePermissions(perms);
44
                             defer.resolve(permissions);
49
                             defer.resolve(permissions);
45
                         }, defer.reject);
50
                         }, defer.reject);
46
                     return defer.promise;
51
                     return defer.promise;
50
                 {
55
                 {
51
                     var defer = $q.defer();
56
                     var defer = $q.defer();
52
                     luticateRequest.post("/api/luticate/users/logout", null, null, promise)
57
                     luticateRequest.post("/api/luticate/users/logout", null, null, promise)
53
-                        .then(function(data)
58
+                        .finally(function()
54
                         {
59
                         {
55
                             luticateAuthCache.removeUser();
60
                             luticateAuthCache.removeUser();
56
-                            defer.resolve(null);
57
-                        }, function(error)
58
-                        {
59
-                            luticateAuthCache.removeUser();
60
-                            defer.resolve(null);
61
+                            luticateAuthUsers.loadPermissions(promise)
62
+                                .finally(defer.resolve);
61
                         });
63
                         });
62
                     return defer.promise;
64
                     return defer.promise;
63
                 };
65
                 };

Loading…
Cancel
Save