浏览代码

begin auth

tags/0.1.0
Robin Thoni 9 年前
父节点
当前提交
c09e0998c8
共有 4 个文件被更改,包括 97 次插入0 次删除
  1. 20
    0
      bower.json
  2. 39
    0
      src/cache.js
  3. 7
    0
      src/luticateauth.js
  4. 31
    0
      src/users.js

+ 20
- 0
bower.json 查看文件

@@ -0,0 +1,20 @@
1
+{
2
+  "name": "luticate-auth",
3
+  "version": "0.0.0",
4
+  "authors": [
5
+    "Robin THONI <robin@rthoni.com>"
6
+  ],
7
+  "description": "Luticate front authentication layer",
8
+  "license": "MIT",
9
+  "ignore": [
10
+    "**/.*",
11
+    "node_modules",
12
+    "bower_components",
13
+    "test",
14
+    "tests"
15
+  ],
16
+  "dependencies": {
17
+    "luticate-utils": "https://git.rthoni.com/repos/luticate-front/utils.git",
18
+    "angular-local-storage": "~0.2.3"
19
+  }
20
+}

+ 39
- 0
src/cache.js 查看文件

@@ -0,0 +1,39 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+
8
+    angular.module('luticateAuth')
9
+        .factory('luticateAuthCache', ['localStorageService', function (localStorageService) {
10
+
11
+            var luticateAuthCache = {};
12
+
13
+            luticateAuthCache.setUser = function(user)
14
+            {
15
+                localStorageService.set('lu_user', user);
16
+            };
17
+
18
+            luticateAuthCache.getUser = function()
19
+            {
20
+                return localStorageService.get('lu_user');
21
+            };
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
+            luticateAuthCache.removeUser = function()
33
+            {
34
+                localStorageService.remove('lu_user');
35
+            };
36
+
37
+            return luticateAuthCache;
38
+        }]);
39
+})();

+ 7
- 0
src/luticateauth.js 查看文件

@@ -0,0 +1,7 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function() {
6
+    angular.module("luticateAuth", []);
7
+})();

+ 31
- 0
src/users.js 查看文件

@@ -0,0 +1,31 @@
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',
9
+            function(luticateRequest, $q, luticateAuthCache) {
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(data)
18
+                    {
19
+                        luticateAuthCache.setUser(data);
20
+                        defer.resolve(data);
21
+                    }, function(error)
22
+                    {
23
+                        luticateAuthCache.removeUser();
24
+                        defer.reject(error);
25
+                    });
26
+                return defer.promise;
27
+            };
28
+
29
+            return luticateAuthUsers;
30
+        }]);
31
+})();

正在加载...
取消
保存