-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.js
executable file
·75 lines (69 loc) · 1.62 KB
/
login.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
var User = require('./models/user');
exports.fake = function(req, res, next) {
if (req.user !== undefined) {
next();
} else if( process.env.DEV_USER !== undefined && process.env.DEV_USER != 'none' )
{
User.fetch( process.env.DEV_USER, function( err, user ) {
console.log('faking user', user.netID);
req.user = user;
next();
});
} else {
next();
}
};
exports.ensure = function(req, res, next) {
if( process.env.DEV_USER != undefined && process.env.DEV_USER != 'none' )
{
User.fetch( process.env.DEV_USER, function( err, user ) {
req.user = user;
next();
});
}
else
{
if( req.user == undefined )
{
res.redirect( process.env.base_url + '/auth/start?next=' + encodeURIComponent( process.env.base_url + req.url ) );
}
else
{
next();
}
}
// if (typeof options == 'string') {
// options = { redirectTo: options }
// }
// options = options || {};
//
// var url = options.redirectTo || '/login';
// var setReturnTo = (options.setReturnTo === undefined) ? true : options.setReturnTo;
//
// return function(req, res, next) {
// if (!req.isAuthenticated || !req.isAuthenticated()) {
// if (setReturnTo && req.session) {
// req.session.returnTo = req.url;
// }
// return res.redirect(url);
// }
// next();
// }
}
exports.access_admin = [
exports.ensure,
function(req, res, next) {
if( req.user == undefined )
{
res.redirect( process.env.base_url + '/auth/start?next=' + process.env.base_url + req.url );
}
else if( !req.user.can('access_groups') )
{
res.redirect( process.env.base_url );
}
else
{
next();
}
}
];