-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
69 lines (63 loc) · 2.44 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
(function () {
'use strict';
angular
.module('app', ['ui.router', 'ngMessages', 'ngStorage', 'induction.authentication', 'induction.course', 'induction.question', 'induction.scorecard', 'induction.admin'])
.config(config)
.run(run);
function config($stateProvider, $urlRouterProvider) {
// app routes
$stateProvider
.state('course', {
url: '/',
templateUrl: 'course/index.view.html',
controller: 'Course.IndexController',
controllerAs: 'cm'
})
.state('scorecard', {
url: '/scorecard',
templateUrl: 'course/scorecard.view.html',
controller: 'Course.ScorecardController',
controllerAs: 'scorecardurl'
})
.state('questions', {
url: '/questions',
templateUrl: 'course/question.view.html',
controller: 'Questions.IndexController',
controllerAs: 'qm'
})
.state('login', {
url: '/login',
templateUrl: 'login/index.view.html',
controller: 'Login.IndexController',
controllerAs: 'vm'
})
.state('admin', {
url: '/admin',
templateUrl: 'admin/admin.view.html',
controller: 'Admin.Controller',
controllerAs: 'admin'
});
// default route
$urlRouterProvider.otherwise("/");
}
function run($rootScope, $http, $location, $localStorage) {
// keep user logged in after page refresh
if ($localStorage.currentUser) {
$rootScope.showLogin = true;
if($localStorage.currentUser.role == 'admin'){
$rootScope.showAdmin = true;
} else{
$rootScope.showAdmin = false;
}
$http.defaults.headers.common['x-auth-token'] = $localStorage.currentUser.token;
}
// redirect to login page if not logged in and trying to access a restricted page
$rootScope.$on('$locationChangeStart', function (event, next, current) {
var publicPages = ['/login'];
var restrictedPage = publicPages.indexOf($location.path()) === -1;
if (restrictedPage && !$localStorage.currentUser) {
$location.path('/login');
}
});
}
})();