-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-controller.js
executable file
·47 lines (40 loc) · 1.13 KB
/
app-controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
angular.module('app').controller('AppController', AppController);
AppController.$inject = ['$scope', '$route', 'LogInService', '$location', '$timeout'];
function AppController($scope, $route, LogInService, $location, $timeout) {
$scope.$on('user.update', function(event) {
$scope.user = LogInService.currentUser;
});
$scope.$route = $route;
LogInService.redirectIfNoUser();
if (LogInService.getUser() !== false) {
$scope.user = LogInService.getUser();
}
$scope.username = "";
$scope.password = "";
$scope.homelink = function () {
if (LogInService.getUser() !== false) {
console.log('redirecting');
$location.path('/');
}
};
$scope.login = function () {
if ($scope.username && $scope.password) {
LogInService.login($scope.username, $scope.password).then(
function (result) {
if (result === true) {
$location.path('/');
} else {
console.log('Incorrect username or password');
}
});
$scope.username = "";
$scope.password = "";
}
};
$scope.logout = function () {
LogInService.logout();
$location.path('/login');
$scope.username = "";
$scope.password = "";
};
}