-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
75 lines (67 loc) · 2.26 KB
/
main.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
74
75
config.$inject = ['$routeProvider','$locationProvider'];
function config($routeProvider, $locationProvider) {
$routeProvider.when('/', {
controller: 'HomeController',
templateUrl: 'conference_admin/conference_admin.view.html',
controllerAs: 'vm'
}).when('/login', {
controller: 'LoginController',
templateUrl: 'login/login.view.html',
controllerAs: 'vm'
}).when('/choose_conference', {
controller: 'ChooseConferenceController',
templateUrl: 'choose_conference/choose_conference.view.html',
controllerAs: 'vm'
}).when('/manage_account', {
controller: 'ManageAccountController',
templateUrl: 'manage_account/manage_account.view.html',
controllerAs: 'vm'
}).when('/root_admin', {
controller: 'ManageAccountController',
templateUrl: 'root_admin_home/root_admin_home.view.html',
controllerAs: 'vm'
}).otherwise({ redirectTo: '/login' });
}
run.$inject = ['$rootScope', '$location', 'AuthenticationService', 'editableOptions', 'APIServices'];
function run($rootScope, $location, AuthenticationService, editableOptions, APIServices) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
var path = $location.path();
var authRef = APIServices.getAuthRef();
authRef.onAuthStateChanged(function(adata) {
if(adata) {
if(path.indexOf('/login') >= 0) {
$location.path('/');
} else {
$location.path(path);
}
} else {
$location.path('/login');
}
});
$rootScope.$on('$locationChangeStart', function (event, next, current) {
// redirect to login page if not logged in and trying to access a restricted page
//var restrictedPage = $.inArray($location.path(), ['/login']) < 0;
//if(restrictedPage) {
path = $location.path();
AuthenticationService.isLoggedIn().then(function(userInfo) {
if(userInfo) {
if($.inArray(path, ['/manage_account', '/root_admin']) < 0) {
var conference = $location.search().conference;
if(conference) {
$location.path('/');
} else {
$location.path('/choose_conference');
}
}
} else {
$location.path('/login');
}
}, function(err) {
console.error(err);
});
//}
});
}
var app = angular.module('app', ['ngRoute', 'ngCookies', 'xeditable', 'firebase', 'ui.bootstrap', 'ngFileUpload', 'angularMoment'])
.config(config)
.run(run);