Robin Thoni пре 9 година
родитељ
комит
1ed910810f

+ 1
- 1
bower.json Прегледај датотеку

@@ -13,7 +13,7 @@
13 13
     "bootstrap": "3.3.x",
14 14
     "less": "1.7.x",
15 15
     "luticate-utils": "https://git.rthoni.com/repos/luticate-front/utils.git",
16
-    "angular-local-storage": "~0.2.3"
16
+    "luticate-auth": "https://git.rthoni.com/repos/luticate-front/auth.git"
17 17
   },
18 18
   "resolutions": {
19 19
     "angular": "1.4.x"

+ 5
- 3
luticate/app.js Прегледај датотеку

@@ -6,6 +6,7 @@ var luticate = angular.module('luticate', [
6 6
     'ui.bootstrap',
7 7
     'ui.router',
8 8
     'luticateUtils',
9
+    'luticateAuth',
9 10
     'LocalStorageModule'
10 11
 ]);
11 12
 
@@ -44,10 +45,11 @@ luticate.config(['$stateProvider', '$urlRouterProvider', '$httpProvider',
44 45
 
45 46
         $urlRouterProvider.otherwise('/');
46 47
 
47
-        $httpProvider.interceptors.push(['ServiceCache', '$injector', '$q', function (ServiceCache, $injector, $q) {
48
+        $httpProvider.interceptors.push(['luticateAuthCache', '$injector', '$q',
49
+            function (luticateAuthCache, $injector, $q) {
48 50
             return {
49 51
                 'request': function (config) {
50
-                    var token = ServiceCache.getToken();
52
+                    var token = luticateAuthCache.getToken();
51 53
 
52 54
                     if (token != null)
53 55
                         config.headers['X-Authorization'] = token;
@@ -56,7 +58,7 @@ luticate.config(['$stateProvider', '$urlRouterProvider', '$httpProvider',
56 58
                 },
57 59
                 'responseError': function(rejection) {
58 60
                     if (rejection.status == 401) {
59
-                        ServiceCache.removeToken();
61
+                        luticateAuthCache.removeUser();
60 62
                         $injector.get('$state').transitionTo('login');
61 63
                     }
62 64
                     return $q.reject(rejection);

+ 31
- 3
luticate/controllers/login.controller.js Прегледај датотеку

@@ -1,5 +1,33 @@
1 1
 angular.module('luticate')
2
-    .controller('LoginController', ['$scope', '$state', 'luticatePromises',
3
-        function($scope, $state, luticatePromises) {
2
+    .controller('LoginController', ['$scope', '$state', 'luticateAuthUsers', 'luticateAuthCache',
3
+        function($scope, $state, luticateAuthUsers, luticateAuthCache) {
4
+            $scope.username = "";
5
+            $scope.password = "";
6
+            $scope.errorString = null;
4 7
 
5
-    }]);
8
+            var promiseLogin = {
9
+                id: "promiseLogin",
10
+                loaderGroups: ["loginForm"]
11
+            };
12
+
13
+            if (luticateAuthCache.getUser() != null) {
14
+                $state.go('home');
15
+                return;
16
+            }
17
+
18
+            $scope.login = function()
19
+            {
20
+                $scope.errorString = null;
21
+                if ($scope.username != "") {
22
+                    luticateAuthUsers.login({username: $scope.username, password: $scope.password}, promiseLogin)
23
+                        .then(function(user)
24
+                        {
25
+                            $state.go('home');
26
+                        }, function(error)
27
+                        {
28
+                            $scope.errorString = error.Data;
29
+                        });
30
+                }
31
+            };
32
+        }
33
+    ]);

+ 8
- 0
luticate/controllers/navbar.controller.js Прегледај датотеку

@@ -0,0 +1,8 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+angular.module('luticate')
6
+    .controller('NavBarController', ['$scope', '$state', 'luticatePromises',
7
+        function($scope, $state, luticatePromises) {
8
+        }]);

+ 6
- 2
luticate/index.html Прегледај датотеку

@@ -24,11 +24,15 @@
24 24
     <script src="../bower_components/luticate-utils/src/promises.js"></script>
25 25
     <script src="../bower_components/luticate-utils/src/request.js"></script>
26 26
     <script src="../bower_components/luticate-utils/src/lubusy.js"></script>
27
+    <script src="../bower_components/luticate-auth/src/luticateauth.js"></script>
28
+    <script src="../bower_components/luticate-auth/src/users.js"></script>
29
+    <script src="../bower_components/luticate-auth/src/cache.js"></script>
27 30
 
28 31
     <!-- scripts -->
29 32
     <script src="app.js"></script>
30 33
 
31 34
     <!-- Controller -->
35
+    <script src="controllers/navbar.controller.js"></script>
32 36
     <script src="controllers/login.controller.js"></script>
33 37
     <script src="controllers/home.controller.js"></script>
34 38
     <script src="controllers/users.controller.js"></script>
@@ -45,9 +49,9 @@
45 49
 </head>
46 50
 <body>
47 51
 
48
-<ng-include src="'views/headers/header.html'"></ng-include>
52
+<ng-include src="'views/navbar.html'"></ng-include>
49 53
 <div ui-view></div>
50
-<ng-include src="'views/footers/footer.html'"></ng-include>
54
+<ng-include src="'views/footer.html'"></ng-include>
51 55
 
52 56
 </body>
53 57
 </html>

luticate/views/footers/footer.html → luticate/views/footer.html Прегледај датотеку


+ 20
- 0
luticate/views/login.html Прегледај датотеку

@@ -1,6 +1,26 @@
1 1
 <!-- Page Content -->
2 2
 <div class="container">
3 3
     <div class="row">
4
+        <div class="col-sm-offset-4 col-sm-4">
5
+            <h1 class="text-center">Login</h1>
4 6
 
7
+            <form ng-submit="login()" lu-busy="loginForm">
8
+                <label for="login">Username</label><br />
9
+                <input id="login" ng-model="username" class="form-control" />
10
+
11
+                <label for="password">Password</label><br />
12
+                <input id="password" ng-model="password" class="form-control" />
13
+
14
+                <br />
15
+                <div class="col-sm-12 center-block">
16
+                    <button type="submit" class="btn btn-default center-block">Login</button>
17
+                </div>
18
+
19
+                <br />
20
+                <div>
21
+                    <span class="error" ng-show="errorString != null">{{ errorString }}</span>
22
+                </div>
23
+            </form>
24
+        </div>
5 25
     </div>
6 26
 </div>

luticate/views/headers/header.html → luticate/views/navbar.html Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 <body>
2 2
 <!-- Navigation -->
3
-<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
3
+<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" ng-controller="NavBarController">
4 4
     <div class="container">
5 5
         <!-- Brand and toggle get grouped for better mobile display -->
6 6
         <div class="navbar-header">
@@ -19,6 +19,9 @@
19 19
                 <li><a href="#/groups">Groups</a></li>
20 20
                 <li><a href="#/permissions">Permissions</a></li>
21 21
             </ul>
22
+            <ul class="nav navbar-nav navbar-right">
23
+                <li><a href="#">Test</a></li>
24
+            </ul>
22 25
         </div>
23 26
         <!-- /.navbar-collapse -->
24 27
     </div>

+ 0
- 15
sdk/cache.js Прегледај датотеку

@@ -6,21 +6,6 @@
6 6
 
7 7
             var ServiceCache = {};
8 8
 
9
-            ServiceCache.setToken = function(token)
10
-            {
11
-                localStorageService.set('lu_token', token);
12
-            };
13
-
14
-            ServiceCache.getToken = function()
15
-            {
16
-                return localStorageService.get('lu_token');
17
-            };
18
-
19
-            ServiceCache.removeToken = function()
20
-            {
21
-                localStorageService.remove('lu_token');
22
-            };
23
-
24 9
             return ServiceCache;
25 10
         }]);
26 11
 })();

Loading…
Откажи
Сачувај