add cookie
This commit is contained in:
parent
ad02bc3714
commit
a998928202
4 changed files with 13 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
|||
const config = require('../config')
|
||||
const ROUGHLY_ONE_YEAR_IN_MILLISECONDS = 1000 * 60 * 60 * 24 * 30 * 12
|
||||
const COOKIE_NAME = 'christmas_community.guestpassword'
|
||||
|
||||
module.exports = options => {
|
||||
return (req, res, next) => {
|
||||
options = options || {}
|
||||
|
@ -9,12 +11,13 @@ module.exports = options => {
|
|||
return res.send('auth fail')
|
||||
}
|
||||
if (authed) return next()
|
||||
if (_CC.config.guestPassword && req.query.pw === _CC.config.guestPassword) {
|
||||
if (_CC.config.guestPassword && (req.query.pw === _CC.config.guestPassword || req.cookies[COOKIE_NAME] === _CC.config.guestPassword)) {
|
||||
req.user = {
|
||||
_id: '_CCUNKNOWN'
|
||||
}
|
||||
res.cookie(COOKIE_NAME, _CC.config.guestPassword, { maxAge: ROUGHLY_ONE_YEAR_IN_MILLISECONDS })
|
||||
return next()
|
||||
}
|
||||
res.redirect(options.failureRedirect || config.defaultFailureRedirect)
|
||||
res.redirect(options.failureRedirect || _CC.config.defaultFailureRedirect)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue