Browse Source

begin auth

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
c09e0998c8
4 changed files with 97 additions and 0 deletions
  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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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
+})();

Loading…
Cancel
Save