-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauthorization.js
executable file
·61 lines (50 loc) · 1.14 KB
/
authorization.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
/*
* Generic require login routing middleware
*/
requiresApproval = exports.requiresApproval = function (req, res, next) {
if (req.isAuthenticated() && !req.user.approved) {
return res.redirect('/signup/complete')
}
next()
};
exports.requiresLogin = function (req, res, next) {
if (!req.isAuthenticated()) {
return res.redirect('/login')
} else {
return requiresApproval(req,res,next);
}
next()
};
/*
* User authorizations routing middleware
*/
exports.user = {
hasAuthorization: function (req, res, next) {
if (req.profile.id != req.user.id) {
return res.redirect('/users/'+req.profile.id)
}
next()
}
}
/*
* Project authorizations routing middleware
*/
exports.resource = {
hasAuthorization : function (req, res, next) {
if (req.resource.user.id != req.user.id) {
return res.redirect('/resources/' + req.resource.id)
}
next()
}
}
/*
* Project authorizations routing middleware
*/
exports.project = {
hasAuthorization : function (req, res, next) {
if (req.project.user.id != req.user.id) {
return res.redirect('/projects/'+req.project.id)
}
next()
}
}