-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·93 lines (75 loc) · 3.02 KB
/
Copy pathapp.js
File metadata and controls
executable file
·93 lines (75 loc) · 3.02 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
angular.module('gatm', ['ui.bootstrap', 'LocalStorageModule', 'security', 'login', 'signup', 'dashboard',
'angular-flash.service', 'angular-flash.flash-alert-directive']);
angular.module('gatm').config(function($routeProvider,
$locationProvider,
$urlRouterProvider,
localStorageServiceProvider,
flashProvider) {
//setting prefix for storage.
localStorageServiceProvider.setPrefix('tm');
// Support bootstrap 3.0 "alert-danger" class with error flash types
flashProvider.errorClassnames.push('alert-danger');
/**
* Also have...
*
* flashProvider.warnClassnames
* flashProvider.infoClassnames
* flashProvider.successClassnames
*/
/* Add New Routes Above */
//$routeProvider.otherwise({redirectTo:'/home'});
// enable html5Mode for pushstate ('#'-less URLs)
//$locationProvider.html5Mode(true);
//$locationProvider.hashPrefix('!');
//$urlRouterProvider.otherwise('/login');
})
.controller('ApplicationController', function ($scope,
USER_ROLES,
AuthService,
AUTH_EVENTS,
$state) {
$scope.currentUser = null;
$scope.userRoles = USER_ROLES;
$scope.isAuthorized = AuthService.isAuthorized;
$scope.setCurrentUser = function (user) {
$scope.currentUser = user;
};
//change state to login incase of authorisation declined.
$scope.$on(AUTH_EVENTS.notAuthenticated, function (event, data) {
$state.go("login");
});
$scope.$on(AUTH_EVENTS.notAuthorized, function (event, data) {
$state.go("login");
});
});
angular.module('gatm').run(function($rootScope, AuthService, AUTH_EVENTS, $state, SessionService) {
$rootScope.$on('$stateChangeStart', function (event, next) {
var _isSecure = next.data.isSecure;
if(_isSecure) {
if (!AuthService.isAuthenticated()) {
event.preventDefault();
$rootScope.$broadcast(AUTH_EVENTS.notAuthenticated);
}
}
var promise = AuthService.requestCurrentUser();
if (promise) {
promise.then(function (res) {
SessionService.create(res.data.access_token, res.data.username, res.data.roles);
$state.transitionTo('dashboard');
}, function(result) {
//AuthService.clearUpSession();
//$state.transitionTo('login');
});
}
});
$rootScope.safeApply = function(fn) {
var phase = $rootScope.$$phase;
if (phase === '$apply' || phase === '$digest') {
if (fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
});