-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorization.js
More file actions
41 lines (34 loc) · 866 Bytes
/
authorization.js
File metadata and controls
41 lines (34 loc) · 866 Bytes
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
/*
* Generic require login routing middleware
*/
exports.requiresLogin = function (req, res, next) {
if (!req.loggedIn) {
req.flash('notice', 'You are not authorized. Please login')
res.redirect('/')
}
next()
};
/*
* User authorizations routing middleware
*/
exports.user = {
hasAuthorization : function (req, res, next) {
if (req.foundUser.id != req.session.auth.userId) {
req.flash('notice', 'You are not authorized')
res.redirect('/profile/'+req.foundUser.id)
}
next()
}
}
/*
* Article authorizations routing middleware
*/
exports.album = {
hasAuthorization : function (req, res, next) {
if (req.album.users[req.session.auth.userId].rol === 'tree') {
req.flash('notice', 'You are not authorized');
res.redirect('/album/'+req.album.id);
}
next()
}
}