forked from arnaucube/commonroutesAdminWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·78 lines (69 loc) · 1.89 KB
/
Copy pathapp.js
File metadata and controls
executable file
·78 lines (69 loc) · 1.89 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
'use strict';
//var urlapi = "http://localhost:3000/api/";
//var urlapi = "http://192.168.1.36:3000/api/";
var urlapi = "http://37.59.123.45:3000/api/";
// Declare app level module which depends on views, and components
angular.module('adminApp', [
'ngRoute',
'ngMessages',
'angularBootstrapMaterial',
'app.navbar',
'app.signup',
'app.login',
'app.main',
'app.search',
'app.travels',
'app.user',
'app.travel',
'app.network',
'app.userNetwork'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
//$routeProvider.otherwise({redirectTo: '/main'});
if((localStorage.getItem('cic_admin_token')))
{
console.log(window.location.hash);
if((window.location.hash==='#!/login')||(window.location.hash==='#!/signup'))
{
window.location='#!/main';
}
$routeProvider.otherwise({redirectTo: '/main'});
}else{
if((window.location!=='#!/login')||(window.location!=='#!/signup'))
{
console.log('app, user no logged');
localStorage.removeItem('cic_admin_token');
localStorage.removeItem('cic_admin_userdata');
window.location='#!/login';
$routeProvider.otherwise({redirectTo: '/login'});
}
}
}])
.factory('httpInterceptor', function httpInterceptor () {
return {
request: function(config) {
return config;
},
requestError: function(config) {
return config;
},
response: function(res) {
return res;
},
responseError: function(res) {
return res;
}
};
})
.factory('api', function ($http) {
return {
init: function () {
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cic_admin_token');
$http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cic_admin_token');
}
};
})
.run(function (api) {
api.init();
});