forked from madhums/node-express-mongoose-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authorization.js
50 lines (40 loc) · 983 Bytes
/
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
/*
* Generic require login routing middleware
*/
exports.requiresLogin = function (req, res, next) {
if (!req.isAuthenticated()) {
return res.redirect('/login')
}
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()
}
}
/*
* Article authorizations routing middleware
*/
exports.article = {
hasAuthorization : function (req, res, next) {
if (req.article.user.id != req.user.id) {
return res.redirect('/articles/'+req.article.id)
}
next()
}
}
exports.phoneno = {
hasAuthorization : function (req, res, next) {
if (req.phoneno.user.id != req.user.id) {
console.log('req.phoneno.user.id ' + req.phoneno.user.id +'req.user.id' + req.user.id)
return res.redirect('/phonenos/')
}
next()
}
}