-
Notifications
You must be signed in to change notification settings - Fork 0
/
articles.js
57 lines (52 loc) · 1.43 KB
/
articles.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
'use strict';
//Setting up route
angular.module('mean.articles').config(['$stateProvider',
function($stateProvider) {
// Check if the user is connected
var checkLoggedin = function($q, $timeout, $http, $location) {
// Initialize a new promise
var deferred = $q.defer();
// Make an AJAX call to check if the user is logged in
$http.get('/loggedin').success(function(user) {
// Authenticated
if (user !== '0') $timeout(deferred.resolve);
// Not Authenticated
else {
$timeout(deferred.reject);
$location.url('/login');
}
});
return deferred.promise;
};
// states for my app
$stateProvider
.state('all articles', {
url: '/articles',
templateUrl: 'articles/views/list.html',
resolve: {
loggedin: checkLoggedin
}
})
.state('create article', {
url: '/articles/create',
templateUrl: 'articles/views/create.html',
resolve: {
loggedin: checkLoggedin
}
})
.state('edit article', {
url: '/articles/:articleId/edit',
templateUrl: 'articles/views/edit.html',
resolve: {
loggedin: checkLoggedin
}
})
.state('article by id', {
url: '/articles/:articleId',
templateUrl: 'articles/views/view.html',
resolve: {
loggedin: checkLoggedin
}
});
}
]);