34 lines
590 B
JavaScript
Raw Normal View History

/* global WIKI */
2017-04-02 19:56:47 -04:00
2016-08-16 20:56:55 -04:00
/**
* Authentication middleware
*/
module.exports = (req, res, next) => {
2017-02-08 20:52:37 -05:00
// Is user authenticated ?
2016-08-16 20:56:55 -04:00
2017-02-08 20:52:37 -05:00
if (!req.isAuthenticated()) {
2018-06-17 11:12:11 -04:00
if (WIKI.config.public !== true) {
2017-04-02 19:56:47 -04:00
return res.redirect('/login')
} else {
2017-12-24 00:34:47 -05:00
// req.user = rights.guest
2017-04-02 19:56:47 -04:00
res.locals.isGuest = true
}
} else {
2017-04-02 19:56:47 -04:00
res.locals.isGuest = false
2017-02-08 20:52:37 -05:00
}
2016-08-16 20:56:55 -04:00
2017-02-08 20:52:37 -05:00
// Check permissions
2016-08-16 20:56:55 -04:00
2017-12-24 00:34:47 -05:00
// res.locals.rights = rights.check(req)
2017-04-02 19:56:47 -04:00
2017-12-24 00:34:47 -05:00
// if (!res.locals.rights.read) {
// return res.render('error-forbidden')
// }
2017-02-08 20:52:37 -05:00
// Expose user data
2016-08-16 20:56:55 -04:00
2017-02-08 20:52:37 -05:00
res.locals.user = req.user
2016-08-16 20:56:55 -04:00
2017-02-08 20:52:37 -05:00
return next()
}