-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathroutes.js
209 lines (183 loc) · 11.6 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* Smoke Alarm Installation Request Portal (getasmokealarm.org)
*
* Copyright (C) 2015 American Red Cross
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated() && req.user.isActive == 'yes') {
return next();
}
res.set('X-Auth-Required', 'true');
req.session.returnUrl = req.originalUrl;
res.redirect('/login/');
}
function ensureSiteAdmin(req, res, next) {
if (req.user.siteAdmin) {
return next();
}
res.redirect('/');
}
function ensureAccount(req, res, next) {
if (req.user.canPlayRoleOf('account')) {
if (req.app.config.requireAccountVerification) {
if (req.user.roles.account.isVerified !== 'yes' && !/^\/account\/verification\//.test(req.url)) {
return res.redirect('/account/verification/');
}
}
return next();
}
res.redirect('/');
}
function ensureSignupEnabled(req, res, next) {
if (req.app.config.signupEnabled) {
return next();
} else {
return res.redirect('/404');
}
}
exports = module.exports = function(app, passport) {
app.locals.pretty = true;
//front end
app.get('/', require('./views/index').init);
app.post('/', require('./views/index').saveRequest);
// kiosk version
app.get('/kiosk', require('./views/index').init);
app.post('/kiosk', require('./views/index').saveRequest);
// 311 version
app.get('/311', require('./views/index').init);
app.post('/311', require('./views/index').saveRequest);
//sign up
app.all('/signup*', ensureSignupEnabled);
app.get('/signup/', require('./views/signup/index').init);
app.post('/signup/', require('./views/signup/index').signup);
//social sign up
app.post('/signup/social/', require('./views/signup/index').signupSocial);
app.get('/signup/twitter/', passport.authenticate('twitter', { callbackURL: '/signup/twitter/callback/' }));
app.get('/signup/twitter/callback/', require('./views/signup/index').signupTwitter);
app.get('/signup/github/', passport.authenticate('github', { callbackURL: '/signup/github/callback/', scope: ['user:email'] }));
app.get('/signup/github/callback/', require('./views/signup/index').signupGitHub);
app.get('/signup/facebook/', passport.authenticate('facebook', { callbackURL: '/signup/facebook/callback/', scope: ['email'] }));
app.get('/signup/facebook/callback/', require('./views/signup/index').signupFacebook);
app.get('/signup/google/', passport.authenticate('google', { callbackURL: '/signup/google/callback/', scope: ['profile email'] }));
app.get('/signup/google/callback/', require('./views/signup/index').signupGoogle);
app.get('/signup/tumblr/', passport.authenticate('tumblr', { callbackURL: '/signup/tumblr/callback/' }));
app.get('/signup/tumblr/callback/', require('./views/signup/index').signupTumblr);
// sms
app.get('/sms/', require('./views/sms/index').respond);
app.get('/sms/response/', require('./views/sms/response/index').init);
app.post('/sms/response/', require('./views/sms/response/index').status);
//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/:email/:token/', require('./views/login/reset/index').init);
app.put('/login/reset/:email/:token/', require('./views/login/reset/index').set);
app.get('/logout/', require('./views/logout/index').init);
//social login
app.get('/login/twitter/', passport.authenticate('twitter', { callbackURL: '/login/twitter/callback/' }));
app.get('/login/twitter/callback/', require('./views/login/index').loginTwitter);
app.get('/login/github/', passport.authenticate('github', { callbackURL: '/login/github/callback/' }));
app.get('/login/github/callback/', require('./views/login/index').loginGitHub);
app.get('/login/facebook/', passport.authenticate('facebook', { callbackURL: '/login/facebook/callback/' }));
app.get('/login/facebook/callback/', require('./views/login/index').loginFacebook);
app.get('/login/google/', passport.authenticate('google', { callbackURL: '/login/google/callback/', scope: ['profile email'] }));
app.get('/login/google/callback/', require('./views/login/index').loginGoogle);
app.get('/login/tumblr/', passport.authenticate('tumblr', { callbackURL: '/login/tumblr/callback/', scope: ['profile email'] }));
app.get('/login/tumblr/callback/', require('./views/login/index').loginTumblr);
//admin
app.all('/admin*', ensureAuthenticated);
app.get('/admin/', require('./views/admin/index').init);
//admin > requests
app.get('/admin/requests/', require('./views/admin/requests/index').find);
app.get('/admin/requests/unknown/', ensureSiteAdmin);
app.get('/admin/requests/unknown/', require('./views/admin/requests/index').unknown);
app.put('/admin/requests/:id/', require('./views/admin/requests/index').update);
app.get('/admin/requests/:id/', require('./views/admin/requests/index').read);
app.delete('/admin/requests/:id/', require('./views/admin/requests/index').delete);
app.get('/admin/counties/', require('./views/admin/counties/index').list);
//admin > users
app.all('/admin/users*', ensureSiteAdmin);
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.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.post('/admin/accounts/:id/notes/', require('./views/admin/accounts/index').newNote);
app.post('/admin/accounts/:id/status/', require('./views/admin/accounts/index').newStatus);
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.all('/account*', ensureAccount);
app.get('/account/', require('./views/account/index').init);
//account > verification
app.get('/account/verification/', require('./views/account/verification/index').init);
app.post('/account/verification/', require('./views/account/verification/index').resendVerification);
app.get('/account/verification/:token/', require('./views/account/verification/index').verify);
//account > settings
app.get('/account/settings/', require('./views/account/settings/index').init);
app.put('/account/settings/', require('./views/account/settings/index').update);
app.put('/account/settings/identity/', require('./views/account/settings/index').identity);
app.put('/account/settings/password/', require('./views/account/settings/index').password);
//account > settings > social
app.get('/account/settings/twitter/', passport.authenticate('twitter', { callbackURL: '/account/settings/twitter/callback/' }));
app.get('/account/settings/twitter/callback/', require('./views/account/settings/index').connectTwitter);
app.get('/account/settings/twitter/disconnect/', require('./views/account/settings/index').disconnectTwitter);
app.get('/account/settings/github/', passport.authenticate('github', { callbackURL: '/account/settings/github/callback/' }));
app.get('/account/settings/github/callback/', require('./views/account/settings/index').connectGitHub);
app.get('/account/settings/github/disconnect/', require('./views/account/settings/index').disconnectGitHub);
app.get('/account/settings/facebook/', passport.authenticate('facebook', { callbackURL: '/account/settings/facebook/callback/' }));
app.get('/account/settings/facebook/callback/', require('./views/account/settings/index').connectFacebook);
app.get('/account/settings/facebook/disconnect/', require('./views/account/settings/index').disconnectFacebook);
app.get('/account/settings/google/', passport.authenticate('google', { callbackURL: '/account/settings/google/callback/', scope: ['profile email'] }));
app.get('/account/settings/google/callback/', require('./views/account/settings/index').connectGoogle);
app.get('/account/settings/google/disconnect/', require('./views/account/settings/index').disconnectGoogle);
app.get('/account/settings/tumblr/', passport.authenticate('tumblr', { callbackURL: '/account/settings/tumblr/callback/' }));
app.get('/account/settings/tumblr/callback/', require('./views/account/settings/index').connectTumblr);
app.get('/account/settings/tumblr/disconnect/', require('./views/account/settings/index').disconnectTumblr);
//route not found
app.all('*', require('./views/http/index').http404);
};