2020-11-08 13:54:08 -08:00
|
|
|
const config = require('../config')
|
2018-11-20 11:19:58 -08:00
|
|
|
module.exports = options => {
|
|
|
|
return (req, res, next) => {
|
2020-11-08 13:54:08 -08:00
|
|
|
options = options || {}
|
2020-10-29 20:50:36 -07:00
|
|
|
let authed = false
|
|
|
|
try {
|
|
|
|
authed = req.isAuthenticated()
|
|
|
|
} catch {
|
|
|
|
return res.send('auth fail')
|
2018-11-20 11:19:58 -08:00
|
|
|
}
|
2020-10-29 20:50:36 -07:00
|
|
|
if (authed) return next()
|
2022-10-03 07:42:29 -07:00
|
|
|
if (_CC.config.guestPassword && req.query.pw === _CC.config.guestPassword) return next()
|
2020-10-29 20:50:36 -07:00
|
|
|
res.redirect(options.failureRedirect || config.defaultFailureRedirect)
|
2020-11-08 13:54:08 -08:00
|
|
|
}
|
|
|
|
}
|