-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (70 loc) · 2.2 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let app = angular.module('formApp', ['ngRoute', 'ngCookies']);
app.config(function($routeProvider) {
$routeProvider
.when('/reg', {
templateUrl: 'reg.html',
controller: 'formCtrl',
resolve: {
redir: function($location, $rootScope, $cookies) {
if ($cookies.get('userAuth')) {
$location.path('/dash');
}
}
}
})
.when('/dash', {
templateUrl: 'dash.html',
resolve: {
redir: function($location, $rootScope, $cookies) {
if (!$cookies.get('userAuth')) {
$location.path('/login');
}
}
}
})
.when('/login', {
templateUrl: 'login.html',
resolve: {
redir: function($location, $cookies) {
if ($cookies.get('userAuth')) {
$location.path('/dash');
}
}
}
})
.when('/post/:postId', {
templateUrl: 'post.html',
resolve: {
redir: function($location, $cookies) {
if ($location.$$hash.indexOf('comment') >= 0) {
if (!$cookies.get('userAuth')) {
$location.path('/dash');
}
}
}
}
})
.when('/news/:page', {
templateUrl: 'news.html'
})
.when('/logout', {
resolve: {
logout: function($rootScope, $location, $cookies) {
$location.path('/');
$cookies.remove('userAuth');
}
}
})
.otherwise({
templateUrl: 'news.html'
});
})
app.run(function($rootScope, $cookies) {;
$rootScope.siteTitle = 'AngularJS Test'
$rootScope.isAuth = function() {
return $cookies.get('userAuth');
}
$rootScope.pageTitle = 'AngularJS Test'
$rootScope.testUsername = 'Test-user';
$rootScope.server = 'https://jsonplaceholder.typicode.com';
});