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
|
/*
* Copyright (c) 2014 Inocybe Technologies, and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
define(['angularAMD', 'jquery', 'common/authentification/auth.module', 'ocLazyLoad'], function (ng, $) {
var login = angular.module('app.common.login', ['app.common.auth', 'ui.router.state']);
login.config(function ($stateProvider, $httpProvider) {
$stateProvider
.state('login', {
url: '/login',
views: {
'mainContent@': {
templateUrl: 'src/common/login/login.tpl.html',
controller: 'LoginCtrl'
}
},
resolve: {
loadController: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load({
files: ['src/common/login/login.controller.js']
});
}]
}
});
$httpProvider.interceptors.push('NbInterceptor');
});
login.run(function ($rootScope, $location, Auth) {
// to avoid recursive loop
var publicPath = ['/login'];
var isPublicPath = function (route) {
var found = false;
$.each(publicPath, function (key, value) {
found = found || route.match('^' + value);
});
return found;
};
$rootScope.$on('$stateChangeStart', function () {
if (!isPublicPath($location.url()) && !Auth.isAuthed()) {
$location.path('/login');
}
});
});
return login;
});
|