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