浏览代码

login/logout

develop
Robin Thoni 9 年前
父节点
当前提交
6df8eef893

+ 8
- 10
luticate/controllers/login.controller.js 查看文件

@@ -19,16 +19,14 @@ angular.module('luticate')
19 19
             $scope.login = function()
20 20
             {
21 21
                 $scope.errorString = null;
22
-                if ($scope.username != "") {
23
-                    luticateAuthUsers.login({username: $scope.username, password: $scope.password}, promiseLogin)
24
-                        .then(function(user)
25
-                        {
26
-                            $state.go('home');
27
-                        }, function(error)
28
-                        {
29
-                            $scope.errorString = error.Data;
30
-                        });
31
-                }
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
+                    });
32 30
             };
33 31
         }
34 32
     ]);

+ 23
- 2
luticate/controllers/navbar.controller.js 查看文件

@@ -3,6 +3,27 @@
3 3
  */
4 4
 
5 5
 angular.module('luticate')
6
-    .controller('NavBarController', ['$scope', '$state', 'luticatePromises',
7
-        function($scope, $state, luticatePromises) {
6
+    .controller('NavBarController', ['$scope', 'luticateAuthCache', 'luticateAuthUsers', '$state',
7
+        function($scope, luticateAuthCache, luticateAuthUsers, $state) {
8
+            var promiseLogout = {
9
+                id: "promiseLogout",
10
+                loaderGroups: ["body"]
11
+            };
12
+
13
+            $scope.hasPermission = function(permission)
14
+            {
15
+                var permissions = luticateAuthCache.getEffectivePermissions();
16
+                if (permissions == null || permissions[permission] == null) {
17
+                    return false;
18
+                }
19
+                return permissions[permission];
20
+            };
21
+
22
+            $scope.logout = function()
23
+            {
24
+                luticateAuthUsers.logout(promiseLogout).finally(function()
25
+                {
26
+                    $state.go('login');
27
+                });
28
+            }
8 29
         }]);

+ 1
- 1
luticate/index.html 查看文件

@@ -59,7 +59,7 @@
59 59
     <!-- Directives -->
60 60
 
61 61
 </head>
62
-<body>
62
+<body lu-busy="body">
63 63
 
64 64
 <ng-include src="'views/navbar.html'"></ng-include>
65 65
 <div ui-view></div>

+ 2
- 2
luticate/views/login.html 查看文件

@@ -6,10 +6,10 @@
6 6
 
7 7
             <form ng-submit="login()" lu-busy="loginForm">
8 8
                 <label for="login">Username</label><br />
9
-                <input id="login" ng-model="username" class="form-control" />
9
+                <input id="login" ng-model="username" class="form-control" required/>
10 10
 
11 11
                 <label for="password">Password</label><br />
12
-                <input id="password" ng-model="password" type="password" class="form-control" />
12
+                <input id="password" ng-model="password" type="password" class="form-control" required/>
13 13
 
14 14
                 <br />
15 15
                 <div class="col-sm-12 center-block">

+ 4
- 4
luticate/views/navbar.html 查看文件

@@ -15,12 +15,12 @@
15 15
         <!-- Collect the nav links, forms, and other content for toggling -->
16 16
         <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
17 17
             <ul class="nav navbar-nav navbar-left">
18
-                <li><a href="#/users">Users</a></li>
19
-                <li><a href="#/groups">Groups</a></li>
20
-                <li><a href="#/permissions">Permissions</a></li>
18
+                <li><a href="#/users" ng-show="hasPermission('LU_USER_GET')">Users</a></li>
19
+                <li><a href="#/groups" ng-show="hasPermission('LU_GROUP_GET')">Groups</a></li>
20
+                <li><a href="#/permissions" ng-show="hasPermission('LU_PERM_GET')">Permissions</a></li>
21 21
             </ul>
22 22
             <ul class="nav navbar-nav navbar-right">
23
-                <li><a href="#">Test</a></li>
23
+                <li><a href="" ng-click="logout()">Logout</a></li>
24 24
             </ul>
25 25
         </div>
26 26
         <!-- /.navbar-collapse -->

正在加载...
取消
保存