Browse Source

login page

develop
Robin Thoni 9 years ago
parent
commit
1ed910810f

+ 1
- 1
bower.json View File

13
     "bootstrap": "3.3.x",
13
     "bootstrap": "3.3.x",
14
     "less": "1.7.x",
14
     "less": "1.7.x",
15
     "luticate-utils": "https://git.rthoni.com/repos/luticate-front/utils.git",
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
   "resolutions": {
18
   "resolutions": {
19
     "angular": "1.4.x"
19
     "angular": "1.4.x"

+ 5
- 3
luticate/app.js View File

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

+ 31
- 3
luticate/controllers/login.controller.js View File

1
 angular.module('luticate')
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 View File

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

24
     <script src="../bower_components/luticate-utils/src/promises.js"></script>
24
     <script src="../bower_components/luticate-utils/src/promises.js"></script>
25
     <script src="../bower_components/luticate-utils/src/request.js"></script>
25
     <script src="../bower_components/luticate-utils/src/request.js"></script>
26
     <script src="../bower_components/luticate-utils/src/lubusy.js"></script>
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
     <!-- scripts -->
31
     <!-- scripts -->
29
     <script src="app.js"></script>
32
     <script src="app.js"></script>
30
 
33
 
31
     <!-- Controller -->
34
     <!-- Controller -->
35
+    <script src="controllers/navbar.controller.js"></script>
32
     <script src="controllers/login.controller.js"></script>
36
     <script src="controllers/login.controller.js"></script>
33
     <script src="controllers/home.controller.js"></script>
37
     <script src="controllers/home.controller.js"></script>
34
     <script src="controllers/users.controller.js"></script>
38
     <script src="controllers/users.controller.js"></script>
45
 </head>
49
 </head>
46
 <body>
50
 <body>
47
 
51
 
48
-<ng-include src="'views/headers/header.html'"></ng-include>
52
+<ng-include src="'views/navbar.html'"></ng-include>
49
 <div ui-view></div>
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
 </body>
56
 </body>
53
 </html>
57
 </html>

luticate/views/footers/footer.html → luticate/views/footer.html View File


+ 20
- 0
luticate/views/login.html View File

1
 <!-- Page Content -->
1
 <!-- Page Content -->
2
 <div class="container">
2
 <div class="container">
3
     <div class="row">
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
     </div>
25
     </div>
6
 </div>
26
 </div>

luticate/views/headers/header.html → luticate/views/navbar.html View File

1
 <body>
1
 <body>
2
 <!-- Navigation -->
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
     <div class="container">
4
     <div class="container">
5
         <!-- Brand and toggle get grouped for better mobile display -->
5
         <!-- Brand and toggle get grouped for better mobile display -->
6
         <div class="navbar-header">
6
         <div class="navbar-header">
19
                 <li><a href="#/groups">Groups</a></li>
19
                 <li><a href="#/groups">Groups</a></li>
20
                 <li><a href="#/permissions">Permissions</a></li>
20
                 <li><a href="#/permissions">Permissions</a></li>
21
             </ul>
21
             </ul>
22
+            <ul class="nav navbar-nav navbar-right">
23
+                <li><a href="#">Test</a></li>
24
+            </ul>
22
         </div>
25
         </div>
23
         <!-- /.navbar-collapse -->
26
         <!-- /.navbar-collapse -->
24
     </div>
27
     </div>

+ 0
- 15
sdk/cache.js View File

6
 
6
 
7
             var ServiceCache = {};
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
             return ServiceCache;
9
             return ServiceCache;
25
         }]);
10
         }]);
26
 })();
11
 })();

Loading…
Cancel
Save