forked from KardiaIO/kardia-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
85 lines (69 loc) · 2.17 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;(function(){
'use strict';
angular.module('ekg', [
'ekg.auth',
'ekg.home',
'ui.router',
'ngMaterial',
'ngMorph'
])
.run(function($rootScope, $state, Auth){
$rootScope.$on("$stateChangeSuccess", function(event, toState, toParams, fromState, fromParams){
if (toState.authenticate && !Auth.isAuth()){
// User isn’t authenticated but the state requires authentication
$state.transitionTo('signin');
event.preventDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider, $httpProvider){
// AngularUI Router uses the concept of states
// Documentation: https://github.com/angular-ui/ui-router
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'components/analysis/home.html',
controller: 'MainController',
authenticate: true
})
.state('signin', {
url: '/signin',
templateUrl: 'components/signin/signin.html',
controller: 'AuthController'
})
.state('signup', {
url: '/signup',
templateUrl: 'components/signin/signup.html',
controller: 'AuthController'
});
// The default route should point to the home page
// which contains the graphs
$urlRouterProvider.otherwise('/home');
//We add $httpInterceptor into the array
$httpProvider.interceptors.push('AttachTokens');
})
.controller('SignInCtrl', ['$scope', function ($scope) {
$scope.example1 = {
closeEl: '.close',
modal: {
templateUrl: 'components/signin/loginform.html'
}
};
}])
.factory('AttachTokens', function ($window) {
// This is an $httpInterceptor. Its job is to stop all out going requests
// then look in local storage and find the user's token.
// Then, add it to the header so the server can validate the request
var attach = {
request: function (object) {
var jwt = $window.localStorage.getItem('com.ekgtracker');
if (jwt) {
object.headers['x-access-token'] = jwt;
}
object.headers['Allow-Control-Allow-Origin'] = '*';
return object;
}
};
return attach;
});
})();