Robin Thoni vor 8 Jahren
Ursprung
Commit
1976836675

+ 18
- 0
public/app/app.js Datei anzeigen

@@ -33,6 +33,24 @@ angular.module('app', [
33 33
                 controller:'HomeController'
34 34
             });
35 35
 
36
+            $stateProvider.state('login', {
37
+                url:'/login',
38
+                parent: 'root',
39
+                title: "Login",
40
+                reloadOnSearch: false,
41
+                templateUrl:'views/login.html',
42
+                controller:'LoginController'
43
+            });
44
+
45
+            $stateProvider.state('signUp', {
46
+                url:'/signUp',
47
+                parent: 'root',
48
+                title: "Sign Up",
49
+                reloadOnSearch: false,
50
+                templateUrl:'views/signup.html',
51
+                controller:'SignUpController'
52
+            });
53
+
36 54
             $urlRouterProvider.otherwise('/');
37 55
     }])
38 56
     .directive('dateNow', ['$filter', function($filter) {

+ 27
- 0
public/app/controllers/login.controller.js Datei anzeigen

@@ -0,0 +1,27 @@
1
+angular.module('app')
2
+    .controller('LoginController', ['$scope', '$state', '$mdDialog', 'luticateAuthUsers',
3
+        function($scope, $state, $mdDialog, luticateAuthUsers) {
4
+            
5
+            $scope.user = {
6
+                Username: "",
7
+                Password: ""
8
+            };
9
+
10
+            $scope.error = null;
11
+            
12
+            $scope.login = function()
13
+            {
14
+                if ($scope.user.Username == "" || $scope.user.Password == "") {
15
+                    return;
16
+                }
17
+                luticateAuthUsers.login({
18
+                    username: $scope.user.Username,
19
+                    password: $scope.user.Password
20
+                }).then(function(data)
21
+                {
22
+                    $state.go("home");
23
+                }, function (error) {
24
+                    $scope.error = error;
25
+                });
26
+            };
27
+    }]);

+ 4
- 0
public/app/controllers/signup.controller.js Datei anzeigen

@@ -0,0 +1,4 @@
1
+angular.module('app')
2
+    .controller('SignUpController', ['$scope', '$state', '$mdDialog',
3
+        function($scope, $state, $mdDialog) {
4
+    }]);

+ 10
- 2
public/app/controllers/toolbar.controller.js Datei anzeigen

@@ -3,11 +3,19 @@
3 3
  */
4 4
 
5 5
 angular.module('app')
6
-    .controller('ToolBarController', ['$scope', '$state', '$mdSidenav',
7
-        function($scope, $state, $mdSidenav) {
6
+    .controller('ToolBarController', ['$scope', '$state', '$mdSidenav', 'luticateAuthCache',
7
+        function($scope, $state, $mdSidenav, luticateAuthCache) {
8 8
 
9 9
                 $scope.toggleSideBar = function()
10 10
                 {
11 11
                     $mdSidenav('left').toggle();
12 12
                 };
13
+                
14
+                $scope.getCurrentUser = function () {
15
+                        return luticateAuthCache.getUser();
16
+                };
17
+
18
+                $scope.isLogged = function () {
19
+                        return $scope.getCurrentUser() != null;
20
+                };
13 21
         }]);

+ 2
- 0
public/app/index.html Datei anzeigen

@@ -50,6 +50,8 @@
50 50
     <script src="controllers/sidebar.controller.js"></script>
51 51
     <script src="controllers/toolbar.controller.js"></script>
52 52
     <script src="controllers/home.controller.js"></script>
53
+    <script src="controllers/login.controller.js"></script>
54
+    <script src="controllers/signup.controller.js"></script>
53 55
 
54 56
     <!-- Modal Controller -->
55 57
 

+ 5
- 0
public/app/less/app.less Datei anzeigen

@@ -31,3 +31,8 @@
31 31
 /**
32 32
 ========================================================
33 33
 **/
34
+
35
+.error-message {
36
+  color: red;
37
+  font-weight: bold;
38
+}

+ 26
- 0
public/app/views/login.html Datei anzeigen

@@ -0,0 +1,26 @@
1
+<div layout="column" layout-fill layout-align="top center">
2
+    <h1>Login</h1>
3
+    <div class="col-xs-4">
4
+        <form ng-submit="login()">
5
+            <div>
6
+                <md-input-container class="col-xs-12">
7
+                    <label for="username">Username</label>
8
+                    <input name="username" id="username" type="text" ng-model="user.Username" required>
9
+                </md-input-container>
10
+            </div>
11
+            <div>
12
+                <md-input-container class="col-xs-12">
13
+                    <label for="password">Password</label>
14
+                    <input name="password" id="password" type="password" ng-model="user.Password" required>
15
+                </md-input-container>
16
+            </div>
17
+            <div class="col-xs-10 col-xs-offset-1">
18
+                <md-button class="col-xs-12" type="submit">Login</md-button>
19
+            </div>
20
+        </form>
21
+        <div class="clearfix"></div>
22
+        <div ng-hide="error == null" class="error-message text-center">
23
+            {{ error.Data }}
24
+        </div>
25
+    </div>
26
+</div>

+ 5
- 0
public/app/views/signup.html Datei anzeigen

@@ -0,0 +1,5 @@
1
+<div layout="column" layout-fill layout-align="top center">
2
+    <p>
3
+        Welcome home
4
+    </p>
5
+</div>

+ 2
- 0
public/app/views/toolbar.html Datei anzeigen

@@ -5,5 +5,7 @@
5 5
         </md-button>
6 6
         <h2>Toolbar</h2>
7 7
         <span flex></span>
8
+        <span ng-hide="isLogged()"><a ui-sref="login">Login</a></span>
9
+        <span ng-show="isLogged()"><a ui-sref="login">{{ getCurrentUser().Firstname }} {{ getCurrentUser().Lastname }}</a></span>
8 10
     </div>
9 11
 </md-toolbar>

Laden…
Abbrechen
Speichern