-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathroutes.js
135 lines (119 loc) · 6.78 KB
/
routes.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
var passport = require('passport');
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) return next();
res.set('X-Auth-Required', 'true');
res.redirect('/login/?returnUrl='+ encodeURIComponent(req.originalUrl));
}
function ensureAdmin(req, res, next) {
if (req.user.canPlayRoleOf('admin')) return next();
res.redirect('/');
}
function ensureAccount(req, res, next) {
if (req.user.canPlayRoleOf('account')) return next();
res.redirect('/');
}
exports = module.exports = function(app) {
//front end
app.get('/', require('./views/index').init);
app.get('/about/', require('./views/about/index').init);
app.get('/contact/', require('./views/contact/index').init);
app.post('/contact/', require('./views/contact/index').sendMessage);
//sign up
app.get('/signup/', require('./views/signup/index').init);
app.post('/signup/', require('./views/signup/index').signup);
//login/out
app.get('/login/', require('./views/login/index').init);
app.post('/login/', require('./views/login/index').login);
app.get('/login/forgot/', require('./views/login/forgot/index').init);
app.post('/login/forgot/', require('./views/login/forgot/index').send);
app.get('/login/reset/', require('./views/login/reset/index').init);
app.get('/login/reset/:token/', require('./views/login/reset/index').init);
app.put('/login/reset/:token/', require('./views/login/reset/index').set);
app.get('/logout/', require('./views/logout/index').init);
//3rd party authentications
app.get('/auth/twitter', passport.authenticate('twitter', { failureRedirect: '/login/' }), function(req, res){
// The request will be redirected to Twitter for authentication, so this
// function will not be called.
console.log('twitter auth: - strange call in authentication');
});
app.get('/auth/twitter/callback', passport.authenticate('twitter', { failureRedirect: '/login/' }), function(req, res) {
console.log('the user is active: ' + req.user.isActive );
console.log('request authenticated: ' + req.isAuthenticated());
if(req.user.isActive == 'yes'){
res.redirect(req.user.defaultReturnUrl());
}
else {
res.redirect('/account/');
}
});
app.get('/auth/github', passport.authenticate('github', { failureRedirect: '/login/' }), function(req, res){
// The request will be redirected to Twitter for authentication, so this
// function will not be called.
console.log('github auth: - strange call in authentication');
});
app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login/' }), function(req, res) {
console.log('the user is active: ' + req.user.isActive );
console.log('request authenticated: ' + req.isAuthenticated());
if(req.user.isActive == 'yes'){
res.redirect(req.user.defaultReturnUrl());
}
else {
res.redirect('/account/');
}
});
//admin
app.all('/admin*', ensureAuthenticated);
app.all('/admin*', ensureAdmin);
app.get('/admin/', require('./views/admin/index').init);
//admin > users
app.get('/admin/users/', require('./views/admin/users/index').find);
app.post('/admin/users/', require('./views/admin/users/index').create);
app.get('/admin/users/:id/', require('./views/admin/users/index').read);
app.put('/admin/users/:id/', require('./views/admin/users/index').update);
app.put('/admin/users/:id/password/', require('./views/admin/users/index').password);
app.put('/admin/users/:id/role-admin/', require('./views/admin/users/index').linkAdmin);
app.put('/admin/users/:id/role-admin/', require('./views/admin/users/index').linkAdmin);
app.delete('/admin/users/:id/role-admin/', require('./views/admin/users/index').unlinkAdmin);
app.put('/admin/users/:id/role-account/', require('./views/admin/users/index').linkAccount);
app.delete('/admin/users/:id/role-account/', require('./views/admin/users/index').unlinkAccount);
app.delete('/admin/users/:id/', require('./views/admin/users/index').delete);
//admin > administrators
app.get('/admin/administrators/', require('./views/admin/administrators/index').find);
app.post('/admin/administrators/', require('./views/admin/administrators/index').create);
app.get('/admin/administrators/:id/', require('./views/admin/administrators/index').read);
app.put('/admin/administrators/:id/', require('./views/admin/administrators/index').update);
app.put('/admin/administrators/:id/permissions/', require('./views/admin/administrators/index').permissions);
app.put('/admin/administrators/:id/groups/', require('./views/admin/administrators/index').groups);
app.put('/admin/administrators/:id/user/', require('./views/admin/administrators/index').linkUser);
app.delete('/admin/administrators/:id/user/', require('./views/admin/administrators/index').unlinkUser);
app.delete('/admin/administrators/:id/', require('./views/admin/administrators/index').delete);
//admin > admin groups
app.get('/admin/admin-groups/', require('./views/admin/admin-groups/index').find);
app.post('/admin/admin-groups/', require('./views/admin/admin-groups/index').create);
app.get('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').read);
app.put('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').update);
app.put('/admin/admin-groups/:id/permissions/', require('./views/admin/admin-groups/index').permissions);
app.delete('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').delete);
//admin > accounts
app.get('/admin/accounts/', require('./views/admin/accounts/index').find);
app.post('/admin/accounts/', require('./views/admin/accounts/index').create);
app.get('/admin/accounts/:id/', require('./views/admin/accounts/index').read);
app.put('/admin/accounts/:id/', require('./views/admin/accounts/index').update);
app.put('/admin/accounts/:id/user/', require('./views/admin/accounts/index').linkUser);
app.delete('/admin/accounts/:id/user/', require('./views/admin/accounts/index').unlinkUser);
app.delete('/admin/accounts/:id/', require('./views/admin/accounts/index').delete);
//admin > search
app.get('/admin/search/', require('./views/admin/search/index').find);
//account
app.all('/account*', ensureAuthenticated);
app.put('/account/*', ensureAccount);
app.get('/account/', require('./views/account/index').init);
app.post('/account/', require('./views/account/index').updateaccount);
app.put('/account/identity/', require('./views/account/index').update);
app.put('/account/password/', require('./views/account/index').password);
app.get('/account/3rdparty/', require('./views/account/index').init);
app.post('/account/3rdparty/remove/:provider/:id/', require('./views/account/index').unlinkProvider);
//main
app.all('/main*', ensureAuthenticated);
app.get('/main/', require('./views/main/index').init);
}