Browse Source

settings; added business/dataaccess

tags/0.1.2
Robin Thoni 4 years ago
parent
commit
0e45caa0bb

+ 2
- 1
Gruntfile.js View File

@@ -10,7 +10,8 @@ module.exports = function(grunt) {
10 10
                 files: {
11 11
                     'dist/luticate-auth.min.js': [
12 12
                         'src/luticateauth.js',
13
-                        'src/*.js'
13
+                        'src/DataAccess/*.js',
14
+                        'src/Business/*.js'
14 15
                     ]
15 16
                 }
16 17
             }

+ 1
- 1
dist/luticate-auth.min.js
File diff suppressed because it is too large
View File


+ 80
- 0
src/Business/cache.js View File

@@ -0,0 +1,80 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+
8
+    angular.module('luticateAuth')
9
+        .factory('luticateAuthCache', ['luticateAuthCacheDataAccess',
10
+            function (luticateAuthCacheDataAccess) {
11
+
12
+            var luticateAuthCache = {
13
+                setUser: luticateAuthCacheDataAccess.setUser,
14
+                getUser: luticateAuthCacheDataAccess.getUser,
15
+                setEffectivePermissions: luticateAuthCacheDataAccess.setEffectivePermissions,
16
+                getEffectivePermissions: luticateAuthCacheDataAccess.getEffectivePermissions,
17
+                removeEffectivePermissions: luticateAuthCacheDataAccess.removeEffectivePermissions,
18
+                setEffectiveSettings: luticateAuthCacheDataAccess.setEffectiveSettings,
19
+                getEffectiveSettings: luticateAuthCacheDataAccess.getEffectiveSettings,
20
+                removeEffectiveSettings: luticateAuthCacheDataAccess.removeEffectiveSettings
21
+            };
22
+
23
+            luticateAuthCache.getToken = function()
24
+            {
25
+                var user = luticateAuthCacheDataAccess.getUser();
26
+                if (user == null) {
27
+                    return null;
28
+                }
29
+                return user.Token;
30
+            };
31
+
32
+            luticateAuthCache.removeUser = function()
33
+            {
34
+                luticateAuthCacheDataAccess.removeUser();
35
+                luticateAuthCacheDataAccess.removeEffectivePermissions();
36
+                luticateAuthCacheDataAccess.removeEffectiveSettings();
37
+            };
38
+
39
+            luticateAuthCache.hasEffectivePermission = function(permission_name)
40
+            {
41
+                var permissions = luticateAuthCacheDataAccess.getEffectivePermissions();
42
+                if (permissions == null) {
43
+                    return null;
44
+                }
45
+                var value = permissions[permission_name];
46
+                return value == null ? null : value;
47
+            };
48
+
49
+            luticateAuthCache.hasAllEffectivePermissions = function(permission_names)
50
+            {
51
+                return !permission_names.some(function(permission_name)
52
+                {
53
+                    return !luticateAuthCache.hasEffectivePermission(permission_name);
54
+                });
55
+            };
56
+
57
+            luticateAuthCache.hasOneEffectivePermission = function(permission_names)
58
+            {
59
+                return permission_names.some(luticateAuthCache.hasEffectivePermission);
60
+            };
61
+
62
+            luticateAuthCache.getEffectiveSetting = function(setting_name)
63
+            {
64
+                var settings = luticateAuthCacheDataAccess.getEffectiveSettings();
65
+                if (settings == null) {
66
+                    return null;
67
+                }
68
+                var value = settings[setting_name];
69
+                return value == null ? null : value;
70
+            };
71
+
72
+            luticateAuthCache.getEffectiveSettingValue = function(setting_name)
73
+            {
74
+                var setting = luticateAuthCacheDataAccess.getEffectiveSetting(setting_name);
75
+                return setting == null ? null : setting.Value;
76
+            };
77
+
78
+            return luticateAuthCache;
79
+        }]);
80
+})();

+ 24
- 0
src/Business/groups.js View File

@@ -0,0 +1,24 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthGroups', ['luticateAuthGroupsDataAccess',
9
+            function(luticateAuthGroupsDataAccess) {
10
+
11
+                var luticateAuthGroups = {
12
+                    getAll: luticateAuthGroupsDataAccess.getAll,
13
+                    get: luticateAuthGroupsDataAccess.get,
14
+                    edit: luticateAuthGroupsDataAccess.edit,
15
+                    add: luticateAuthGroupsDataAccess.add,
16
+                    del: luticateAuthGroupsDataAccess.del,
17
+                    usersGetAll: luticateAuthGroupsDataAccess.usersGetAll,
18
+                    usersAdd: luticateAuthGroupsDataAccess.usersAdd,
19
+                    usersDel: luticateAuthGroupsDataAccess.usersDel
20
+                };
21
+
22
+            return luticateAuthGroups;
23
+        }]);
24
+})();

+ 42
- 0
src/Business/permissions.js View File

@@ -0,0 +1,42 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthPermissions', ['luticateAuthPermissionsDataAccess', 'luticateAuthCache', '$q',
9
+            function(luticateAuthPermissionsDataAccess, luticateAuthCache, $q) {
10
+
11
+                var luticateAuthPermissions = {
12
+                    getAll: luticateAuthPermissionsDataAccess.getAll,
13
+                    get: luticateAuthPermissionsDataAccess.get,
14
+                    edit: luticateAuthPermissionsDataAccess.edit,
15
+                    add: luticateAuthPermissionsDataAccess.add,
16
+                    del: luticateAuthPermissionsDataAccess.del,
17
+                    getEffectiveUser: luticateAuthPermissionsDataAccess.getEffectiveUser,
18
+                    getAllEffectiveUser: luticateAuthPermissionsDataAccess.getAllEffectiveUser,
19
+                    getEffectiveMe: luticateAuthPermissionsDataAccess.getEffectiveMe,
20
+                    getAllEffectiveMe: luticateAuthPermissionsDataAccess.getAllEffectiveMe
21
+                };
22
+
23
+                luticateAuthPermissions.loadPermissions = function(promise)
24
+                {
25
+                    var defer = $q.defer();
26
+                    luticateAuthPermissions.getAllEffectiveMe(promise)
27
+                        .then(function(permissions)
28
+                        {
29
+                            var perms = {};
30
+                            for (var i = 0; i < permissions.Data.length; ++i) {
31
+                                var p = permissions.Data[i];
32
+                                perms[p.Name] = p.Value;
33
+                            }
34
+                            luticateAuthCache.setEffectivePermissions(perms);
35
+                            defer.resolve();
36
+                        }, defer.reject);
37
+                    return defer.promise;
38
+                };
39
+
40
+                return luticateAuthPermissions;
41
+        }]);
42
+})();

+ 21
- 0
src/Business/permissionsgroup.js View File

@@ -0,0 +1,21 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthPermissionsGroup', ['luticateAuthPermissionsGroupDataAccess',
9
+            function(luticateAuthPermissionsGroupDataAccess) {
10
+
11
+                var luticateAuthPermissions = {
12
+                    getAll: luticateAuthPermissionsGroupDataAccess.getAll,
13
+                    get: luticateAuthPermissionsGroupDataAccess.get,
14
+                    edit: luticateAuthPermissionsGroupDataAccess.edit,
15
+                    add: luticateAuthPermissionsGroupDataAccess.add,
16
+                    del: luticateAuthPermissionsGroupDataAccess.del
17
+                };
18
+
19
+                return luticateAuthPermissions;
20
+        }]);
21
+})();

+ 21
- 0
src/Business/permissionsuser.js View File

@@ -0,0 +1,21 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthPermissionsUser', ['luticateAuthPermissionsUserDataAccess',
9
+            function(luticateAuthPermissionsUserDataAccess) {
10
+
11
+                var luticateAuthPermissions = {
12
+                    getAll: luticateAuthPermissionsUserDataAccess.getAll,
13
+                    get: luticateAuthPermissionsUserDataAccess.get,
14
+                    edit: luticateAuthPermissionsUserDataAccess.edit,
15
+                    add: luticateAuthPermissionsUserDataAccess.add,
16
+                    del: luticateAuthPermissionsUserDataAccess.del
17
+                };
18
+
19
+                return luticateAuthPermissions;
20
+        }]);
21
+})();

+ 42
- 0
src/Business/settings.js View File

@@ -0,0 +1,42 @@
1
+/**
2
+ * Created by robin on 01/31/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthSettings', ['luticateAuthSettingsDataAccess', 'luticateAuthCache', '$q',
9
+            function(luticateAuthSettingsDataAccess, luticateAuthCache, $q) {
10
+
11
+                var luticateAuthSettings = {
12
+                    getAll: luticateAuthSettingsDataAccess.getAll,
13
+                    get: luticateAuthSettingsDataAccess.get,
14
+                    edit: luticateAuthSettingsDataAccess.edit,
15
+                    add: luticateAuthSettingsDataAccess.add,
16
+                    del: luticateAuthSettingsDataAccess.del,
17
+                    getEffectiveUser: luticateAuthSettingsDataAccess.getEffectiveUser,
18
+                    getAllEffectiveUser: luticateAuthSettingsDataAccess.getAllEffectiveUser,
19
+                    getEffectiveMe: luticateAuthSettingsDataAccess.getEffectiveMe,
20
+                    getAllEffectiveMe: luticateAuthSettingsDataAccess.getAllEffectiveMe
21
+                };
22
+
23
+                luticateAuthSettings.loadSettings = function(promise)
24
+                {
25
+                    var defer = $q.defer();
26
+                    luticateAuthSettings.getAllEffectiveMe(promise)
27
+                        .then(function(settings)
28
+                        {
29
+                            var sets = {};
30
+                            for (var i = 0; i < settings.Data.length; ++i) {
31
+                                var s = settings.Data[i];
32
+                                sets[s.Name] = s;
33
+                            }
34
+                            luticateAuthCache.setEffectiveSettings(sets);
35
+                            defer.resolve(settings.Data);
36
+                        }, defer.reject);
37
+                    return defer.promise;
38
+                };
39
+
40
+                return luticateAuthSettings;
41
+        }]);
42
+})();

+ 20
- 0
src/Business/settingsuser.js View File

@@ -0,0 +1,20 @@
1
+/**
2
+ * Created by robin on 01/31/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthSettingsUser', ['luticateAuthSettingsUserDataAccess',
9
+            function(luticateAuthSettingsUserDataAccess) {
10
+
11
+                var luticateAuthSettingsUser = {
12
+                    getAll: luticateAuthSettingsUserDataAccess.getAll,
13
+                    get: luticateAuthSettingsUserDataAccess.get,
14
+                    edit: luticateAuthSettingsUserDataAccess.edit,
15
+                    editMe: luticateAuthSettingsUserDataAccess.editMe
16
+                };
17
+
18
+                return luticateAuthSettingsUser;
19
+        }]);
20
+})();

+ 92
- 0
src/Business/users.js View File

@@ -0,0 +1,92 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthUsers', ['luticateAuthUsersDataAccess', '$q', 'luticateAuthCache', 'luticateAuthPermissions', 'luticateAuthSettings',
9
+            function(luticateAuthUsersDataAccess, $q, luticateAuthCache, luticateAuthPermissions, luticateAuthSettings) {
10
+
11
+                var luticateAuthUsers = {
12
+                    getAll: luticateAuthUsersDataAccess.getAll,
13
+                    get: luticateAuthUsersDataAccess.get,
14
+                    getMe: luticateAuthUsersDataAccess.getMe,
15
+                    edit: luticateAuthUsersDataAccess.edit,
16
+                    editMe: luticateAuthUsersDataAccess.editMe,
17
+                    add: luticateAuthUsersDataAccess.add,
18
+                    setPassword: luticateAuthUsersDataAccess.setPassword,
19
+                    setPasswordMe: luticateAuthUsersDataAccess.setPasswordMe,
20
+                    del: luticateAuthUsersDataAccess.del
21
+                };
22
+
23
+                luticateAuthUsers.login = function(data, promise)
24
+                {
25
+                    var defer = $q.defer();
26
+                    luticateAuthUsersDataAccess.login(data, promise)
27
+                        .then(function(user)
28
+                        {
29
+                            luticateAuthCache.setUser(user);
30
+                            luticateAuthUsers.loadUserData(promise).then(function()
31
+                            {
32
+                                defer.resolve(user);
33
+                            }, function(error)
34
+                            {
35
+                                luticateAuthUsers.removeUserData();
36
+                                defer.reject(error);
37
+                            });
38
+                        }, function(error)
39
+                        {
40
+                            luticateAuthUsers.removeUserData();
41
+                            defer.reject(error);
42
+                        });
43
+                    return defer.promise;
44
+                };
45
+
46
+                luticateAuthUsers.logout = function(promise)
47
+                {
48
+                    var defer = $q.defer();
49
+                    luticateAuthUsersDataAccess.logout(promise)
50
+                        .finally(function()
51
+                        {
52
+                            luticateAuthUsers.removeUserData();
53
+                            luticateAuthUsers.loadUserData().finally(defer.resolve);
54
+                        });
55
+                    return defer.promise;
56
+                };
57
+
58
+                luticateAuthUsers.loadUserData = function(promise)
59
+                {
60
+                    luticateAuthCache.removeEffectivePermissions();
61
+                    luticateAuthCache.removeEffectiveSettings();
62
+                    var defer = $q.defer();
63
+                    luticateAuthSettings.loadSettings(promise)
64
+                        .then(function()
65
+                        {
66
+                            luticateAuthPermissions.loadPermissions(promise)
67
+                                .then(defer.resolve, function(error)
68
+                                {
69
+                                    luticateAuthUsers.removeUserData();
70
+                                    defer.reject(error);
71
+                                });
72
+                        }, function(error)
73
+                        {
74
+                            luticateAuthUsers.removeUserData();
75
+                            defer.reject(error);
76
+                        });
77
+                    return defer.promise;
78
+                };
79
+
80
+                //For backward compatibility
81
+                luticateAuthUsers.loadPermissions = luticateAuthUsers.loadUserData;
82
+
83
+                luticateAuthUsers.removeUserData = function()
84
+                {
85
+                    luticateAuthCache.removeEffectivePermissions();
86
+                    luticateAuthCache.removeEffectiveSettings();
87
+                    luticateAuthCache.removeUser();
88
+                };
89
+
90
+            return luticateAuthUsers;
91
+        }]);
92
+})();

src/cache.js → src/DataAccess/cache.js View File

@@ -6,7 +6,7 @@
6 6
     'use strict';
7 7
 
8 8
     angular.module('luticateAuth')
9
-        .factory('luticateAuthCache', ['localStorageService', function (localStorageService) {
9
+        .factory('luticateAuthCacheDataAccess', ['localStorageService', function (localStorageService) {
10 10
 
11 11
             var luticateAuthCache = {};
12 12
 
@@ -20,19 +20,9 @@
20 20
                 return localStorageService.get('lu_user');
21 21
             };
22 22
 
23
-            luticateAuthCache.getToken = function()
24
-            {
25
-                var user = luticateAuthCache.getUser();
26
-                if (user == null) {
27
-                    return null;
28
-                }
29
-                return user.Token;
30
-            };
31
-
32 23
             luticateAuthCache.removeUser = function()
33 24
             {
34 25
                 localStorageService.remove('lu_user');
35
-                luticateAuthCache.removeEffectivePermissions();
36 26
             };
37 27
 
38 28
             luticateAuthCache.setEffectivePermissions = function(permissions)
@@ -45,32 +35,24 @@
45 35
                 return localStorageService.get('lu_effective_permissions');
46 36
             };
47 37
 
48
-            luticateAuthCache.hasEffectivePermission = function(permission_name)
38
+            luticateAuthCache.removeEffectivePermissions = function()
49 39
             {
50
-                var permissions = luticateAuthCache.getEffectivePermissions();
51
-                if (permissions == null) {
52
-                    return null;
53
-                }
54
-                var value = permissions[permission_name];
55
-                return value == null ? null : value;
40
+                localStorageService.remove('lu_effective_permissions');
56 41
             };
57 42
 
58
-            luticateAuthCache.hasAllEffectivePermissions = function(permission_names)
43
+            luticateAuthCache.setEffectiveSettings = function(settings)
59 44
             {
60
-                return !permission_names.some(function(permission_name)
61
-                {
62
-                    return !luticateAuthCache.hasEffectivePermission(permission_name);
63
-                });
45
+                localStorageService.set('lu_effective_settings', settings);
64 46
             };
65 47
 
66
-            luticateAuthCache.hasOneEffectivePermission = function(permission_names)
48
+            luticateAuthCache.getEffectiveSettings = function()
67 49
             {
68
-                return permission_names.some(luticateAuthCache.hasEffectivePermission);
50
+                return localStorageService.get('lu_effective_settings');
69 51
             };
70 52
 
71
-            luticateAuthCache.removeEffectivePermissions = function()
53
+            luticateAuthCache.removeEffectiveSettings = function()
72 54
             {
73
-                localStorageService.remove('lu_effective_permissions');
55
+                localStorageService.remove('lu_effective_settings');
74 56
             };
75 57
 
76 58
             return luticateAuthCache;

src/groups.js → src/DataAccess/groups.js View File

@@ -5,7 +5,7 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticateAuth')
8
-        .factory('luticateAuthGroups', ['luticateRequest',
8
+        .factory('luticateAuthGroupsDataAccess', ['luticateRequest',
9 9
             function(luticateRequest) {
10 10
 
11 11
                 var luticateAuthGroups = {};

src/permissions.js → src/DataAccess/permissions.js View File

@@ -5,7 +5,7 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticateAuth')
8
-        .factory('luticateAuthPermissions', ['luticateRequest',
8
+        .factory('luticateAuthPermissionsDataAccess', ['luticateRequest',
9 9
             function(luticateRequest) {
10 10
 
11 11
                 var luticateAuthPermissions = {};
@@ -50,13 +50,13 @@
50 50
 
51 51
                 luticateAuthPermissions.getEffectiveMe = function(data, promise)
52 52
                 {
53
-                    return luticateRequest.get("/api/luticate/permissions/effective/me/"
54
-                        + data.permission_name, null, promise);
53
+                    data.user_id = "me";
54
+                    return luticateAuthPermissions.getEffectiveUser(data, promise);
55 55
                 };
56 56
 
57 57
                 luticateAuthPermissions.getAllEffectiveMe = function(promise)
58 58
                 {
59
-                    return luticateRequest.get("/api/luticate/permissions/effective/me", null, promise);
59
+                    return luticateAuthPermissions.getAllEffectiveUser({user_id: "me"}, promise);
60 60
                 };
61 61
 
62 62
 

src/permissionsgroup.js → src/DataAccess/permissionsgroup.js View File

@@ -5,7 +5,7 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticateAuth')
8
-        .factory('luticateAuthPermissionsGroup', ['luticateRequest',
8
+        .factory('luticateAuthPermissionsGroupDataAccess', ['luticateRequest',
9 9
             function(luticateRequest) {
10 10
 
11 11
                 var luticateAuthPermissions = {};

src/permissionsuser.js → src/DataAccess/permissionsuser.js View File

@@ -5,7 +5,7 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticateAuth')
8
-        .factory('luticateAuthPermissionsUser', ['luticateRequest',
8
+        .factory('luticateAuthPermissionsUserDataAccess', ['luticateRequest',
9 9
             function(luticateRequest) {
10 10
 
11 11
                 var luticateAuthPermissions = {};

src/settings.js → src/DataAccess/settings.js View File

@@ -5,7 +5,7 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticateAuth')
8
-        .factory('luticateAuthSettings', ['luticateRequest',
8
+        .factory('luticateAuthSettingsDataAccess', ['luticateRequest',
9 9
             function(luticateRequest) {
10 10
 
11 11
                 var luticateAuthSettings = {};

+ 38
- 0
src/DataAccess/settingsuser.js View File

@@ -0,0 +1,38 @@
1
+/**
2
+ * Created by robin on 01/31/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthSettingsUserDataAccess', ['luticateRequest',
9
+            function(luticateRequest) {
10
+
11
+                var luticateAuthSettingsUser = {};
12
+                var url = "/api/luticate/settings/user/";
13
+
14
+                luticateAuthSettingsUser.getAll = function(data, promise)
15
+                {
16
+                    return luticateRequest.get(url + data.user_id, data, promise);
17
+                };
18
+
19
+                luticateAuthSettingsUser.get = function(data, promise)
20
+                {
21
+                    return luticateRequest.get(url + data.user_id + "/" + data.setting_name, null, promise);
22
+                };
23
+
24
+                luticateAuthSettingsUser.edit = function(data, promise)
25
+                {
26
+                    return luticateRequest.post(url + data.user_id + "/" + data.setting_name + "/edit",
27
+                        {setting: JSON.stringify(data.setting)}, null, promise);
28
+                };
29
+
30
+                luticateAuthSettingsUser.editMe = function(data, promise)
31
+                {
32
+                    data.user_id = "me";
33
+                    return luticateAuthSettingsUser.edit(data, promise);
34
+                };
35
+
36
+                return luticateAuthSettingsUser;
37
+        }]);
38
+})();

+ 70
- 0
src/DataAccess/users.js View File

@@ -0,0 +1,70 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthUsersDataAccess', ['luticateRequest',
9
+            function(luticateRequest) {
10
+
11
+                var luticateAuthUsers = {};
12
+
13
+                luticateAuthUsers.login = function(data, promise)
14
+                {
15
+                    return luticateRequest.post("/api/luticate/users/login", data, null, promise);
16
+                };
17
+
18
+                luticateAuthUsers.logout = function(promise)
19
+                {
20
+                    return luticateRequest.post("/api/luticate/users/logout", null, null, promise);
21
+                };
22
+
23
+                luticateAuthUsers.getAll = function(data, promise)
24
+                {
25
+                    return luticateRequest.get("/api/luticate/users", data, promise);
26
+                };
27
+
28
+                luticateAuthUsers.get = function(data, promise)
29
+                {
30
+                    return luticateRequest.get("/api/luticate/users/" + data.user_id, null, promise);
31
+                };
32
+
33
+                luticateAuthUsers.getMe = function(promise)
34
+                {
35
+                    return luticateRequest.get("/api/luticate/users/me", null, promise);
36
+                };
37
+
38
+                luticateAuthUsers.edit = function(data, promise)
39
+                {
40
+                    return luticateRequest.post("/api/luticate/users/" + data.user_id + "/edit", data, null, promise);
41
+                };
42
+
43
+                luticateAuthUsers.editMe = function(data, promise)
44
+                {
45
+                    return luticateRequest.post("/api/luticate/users/me/edit", data, null, promise);
46
+                };
47
+
48
+                luticateAuthUsers.add = function(data, promise)
49
+                {
50
+                    return luticateRequest.post("/api/luticate/users/add", data, null, promise);
51
+                };
52
+
53
+                luticateAuthUsers.setPassword = function(data, promise)
54
+                {
55
+                    return luticateRequest.post("/api/luticate/users/" + data.user_id + "/setPassword", data, null, promise);
56
+                };
57
+
58
+                luticateAuthUsers.setPasswordMe = function(data, promise)
59
+                {
60
+                    return luticateRequest.post("/api/luticate/users/me/setPassword", data, null, promise);
61
+                };
62
+
63
+                luticateAuthUsers.del = function(data, promise)
64
+                {
65
+                    return luticateRequest.post("/api/luticate/users/" + data.user_id + "/del", null, null, promise);
66
+                };
67
+
68
+            return luticateAuthUsers;
69
+        }]);
70
+})();

+ 0
- 121
src/users.js View File

@@ -1,121 +0,0 @@
1
-/**
2
- * Created by robin on 11/1/15.
3
- */
4
-
5
-(function () {
6
-    'use strict';
7
-    angular.module('luticateAuth')
8
-        .factory('luticateAuthUsers', ['luticateRequest', '$q', 'luticateAuthCache', 'luticateAuthPermissions',
9
-            function(luticateRequest, $q, luticateAuthCache, luticateAuthPermissions) {
10
-
11
-                var luticateAuthUsers = {};
12
-
13
-                luticateAuthUsers.login = function(data, promise)
14
-                {
15
-                    var defer = $q.defer();
16
-                    luticateRequest.post("/api/luticate/users/login", data, null, promise)
17
-                        .then(function(user)
18
-                        {
19
-                            luticateAuthCache.setUser(user);
20
-                            luticateAuthUsers.loadPermissions(promise)
21
-                                .then(function(permissions)
22
-                                {
23
-                                    defer.resolve(user);
24
-                                }, function(error)
25
-                                {
26
-                                    luticateAuthCache.removeUser();
27
-                                    defer.reject(error);
28
-                                });
29
-                        }, function(error)
30
-                        {
31
-                            luticateAuthCache.removeUser();
32
-                            luticateAuthUsers.loadPermissions(promise)
33
-                                .then(function(permissions)
34
-                                {
35
-                                    defer.reject(error);
36
-                                }, function(error)
37
-                                {
38
-                                    defer.reject(error);
39
-                                });
40
-                        });
41
-                    return defer.promise;
42
-                };
43
-
44
-                luticateAuthUsers.loadPermissions = function(promise)
45
-                {
46
-                    var defer = $q.defer();
47
-                    luticateAuthPermissions.getAllEffectiveMe(promise)
48
-                        .then(function(permissions)
49
-                        {
50
-                            var perms = {};
51
-                            for (var i = 0; i < permissions.Data.length; ++i) {
52
-                                var p = permissions.Data[i];
53
-                                perms[p.Name] = p.Value;
54
-                            }
55
-                            luticateAuthCache.setEffectivePermissions(perms);
56
-                            defer.resolve(permissions.Data);
57
-                        }, defer.reject);
58
-                    return defer.promise;
59
-                };
60
-
61
-                luticateAuthUsers.logout = function(promise)
62
-                {
63
-                    var defer = $q.defer();
64
-                    luticateRequest.post("/api/luticate/users/logout", null, null, promise)
65
-                        .finally(function()
66
-                        {
67
-                            luticateAuthCache.removeUser();
68
-                            luticateAuthUsers.loadPermissions(promise)
69
-                                .finally(defer.resolve);
70
-                        });
71
-                    return defer.promise;
72
-                };
73
-
74
-                luticateAuthUsers.getAll = function(data, promise)
75
-                {
76
-                    return luticateRequest.get("/api/luticate/users", data, promise);
77
-                };
78
-
79
-                luticateAuthUsers.get = function(data, promise)
80
-                {
81
-                    return luticateRequest.get("/api/luticate/users/" + data.user_id, null, promise);
82
-                };
83
-
84
-                luticateAuthUsers.getMe = function(promise)
85
-                {
86
-                    return luticateRequest.get("/api/luticate/users/me", null, promise);
87
-                };
88
-
89
-                luticateAuthUsers.edit = function(data, promise)
90
-                {
91
-                    return luticateRequest.post("/api/luticate/users/" + data.user_id + "/edit", data, null, promise);
92
-                };
93
-
94
-                luticateAuthUsers.editMe = function(data, promise)
95
-                {
96
-                    return luticateRequest.post("/api/luticate/users/me/edit", data, null, promise);
97
-                };
98
-
99
-                luticateAuthUsers.add = function(data, promise)
100
-                {
101
-                    return luticateRequest.post("/api/luticate/users/add", data, null, promise);
102
-                };
103
-
104
-                luticateAuthUsers.setPassword = function(data, promise)
105
-                {
106
-                    return luticateRequest.post("/api/luticate/users/" + data.user_id + "/setPassword", data, null, promise);
107
-                };
108
-
109
-                luticateAuthUsers.setPasswordMe = function(data, promise)
110
-                {
111
-                    return luticateRequest.post("/api/luticate/users/me/setPassword", data, null, promise);
112
-                };
113
-
114
-                luticateAuthUsers.del = function(data, promise)
115
-                {
116
-                    return luticateRequest.post("/api/luticate/users/" + data.user_id + "/del", null, null, promise);
117
-                };
118
-
119
-            return luticateAuthUsers;
120
-        }]);
121
-})();

Loading…
Cancel
Save