Merge pull request #28 from Wingysam/guest-passwords
Basic Guest Passwords
This commit is contained in:
commit
0e6420f714
10 changed files with 28 additions and 12 deletions
|
@ -15,5 +15,6 @@ module.exports = {
|
||||||
trustProxy: process.env.TRUST_PROXY === 'true' ? true : process.env.TRUST_PROXY || 'loopback',
|
trustProxy: process.env.TRUST_PROXY === 'true' ? true : process.env.TRUST_PROXY || 'loopback',
|
||||||
bulmaswatch: (process.env.BULMASWATCH || 'default').toLowerCase(),
|
bulmaswatch: (process.env.BULMASWATCH || 'default').toLowerCase(),
|
||||||
pfp: process.env.PFP !== 'false',
|
pfp: process.env.PFP !== 'false',
|
||||||
language: process.env.LANGUAGE?.toLowerCase() || 'en-us'
|
language: process.env.LANGUAGE?.toLowerCase() || 'en-us',
|
||||||
|
guestPassword: process.env.GUEST_PASSWORD
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,7 @@ module.exports.strings = {
|
||||||
WISHLIST_PLEDGE_SUCCESS: 'Successfully pledged for item!',
|
WISHLIST_PLEDGE_SUCCESS: 'Successfully pledged for item!',
|
||||||
WISHLIST_PLEDGE: 'Pledge',
|
WISHLIST_PLEDGE: 'Pledge',
|
||||||
WISHLIST_PLEDGED: pledgedBy => `Pledged for by ${pledgedBy}`,
|
WISHLIST_PLEDGED: pledgedBy => `Pledged for by ${pledgedBy}`,
|
||||||
|
WISHLIST_PLEDGED_GUEST: 'Pledged for by a guest user',
|
||||||
WISHLIST_PRICE: 'Price',
|
WISHLIST_PRICE: 'Price',
|
||||||
WISHLIST_REFRESH_GUARD: 'Invalid user',
|
WISHLIST_REFRESH_GUARD: 'Invalid user',
|
||||||
WISHLIST_REFRESH_NO_URL: 'Item has no URL.',
|
WISHLIST_REFRESH_NO_URL: 'Item has no URL.',
|
||||||
|
|
|
@ -2,7 +2,7 @@ const verifyAuth = require('./verifyAuth')
|
||||||
|
|
||||||
const publicMiddleware = () => global._CC.config.wishlist.public
|
const publicMiddleware = () => global._CC.config.wishlist.public
|
||||||
? (req, res, next) => {
|
? (req, res, next) => {
|
||||||
if (!req.user) req.user = { _id: 'Unknown' }
|
if (!req.user) req.user = { _id: '_CCUNKNOWN' }
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
: verifyAuth()
|
: verifyAuth()
|
||||||
|
|
|
@ -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 => {
|
module.exports = options => {
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
options = options || {}
|
options = options || {}
|
||||||
|
@ -9,6 +11,13 @@ module.exports = options => {
|
||||||
return res.send('auth fail')
|
return res.send('auth fail')
|
||||||
}
|
}
|
||||||
if (authed) return next()
|
if (authed) return next()
|
||||||
res.redirect(options.failureRedirect || config.defaultFailureRedirect)
|
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 || _CC.config.defaultFailureRedirect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"child-process-promise": "^2.2.1",
|
"child-process-promise": "^2.2.1",
|
||||||
"connect-flash": "^0.1.1",
|
"connect-flash": "^0.1.1",
|
||||||
|
"cookie-parser": "^1.4.6",
|
||||||
"dompurify": "^2.3.1",
|
"dompurify": "^2.3.1",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"express": "4.17.1",
|
"express": "4.17.1",
|
||||||
|
|
|
@ -29,6 +29,7 @@ module.exports = ({ db, config }) => {
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.use('/', express.static(path.join(__dirname, '../static')))
|
router.use('/', express.static(path.join(__dirname, '../static')))
|
||||||
|
router.use(require('cookie-parser')())
|
||||||
|
|
||||||
router.get('/',
|
router.get('/',
|
||||||
async (req, res, next) => {
|
async (req, res, next) => {
|
||||||
|
|
|
@ -21,7 +21,7 @@ nav.navbar.is-fixed-top(role='navigation', aria-label='main navigation',style='b
|
||||||
.navbar-menu#navBarMenu
|
.navbar-menu#navBarMenu
|
||||||
.navbar-start
|
.navbar-start
|
||||||
if req.isAuthenticated()
|
if req.isAuthenticated()
|
||||||
if req.user._id === 'Unknown'
|
if req.user._id === '_CCUNKNOWN'
|
||||||
.navbar-item
|
.navbar-item
|
||||||
a.button.is-primary(href='/login')= lang('NAVBAR_LOGIN')
|
a.button.is-primary(href='/login')= lang('NAVBAR_LOGIN')
|
||||||
else
|
else
|
||||||
|
|
|
@ -113,7 +113,10 @@ block content
|
||||||
.control.inline
|
.control.inline
|
||||||
input.inline.button(type='submit' value=lang('WISHLIST_UNPLEDGE'))
|
input.inline.button(type='submit' value=lang('WISHLIST_UNPLEDGE'))
|
||||||
if item.pledgedBy && item.pledgedBy !== req.user._id
|
if item.pledgedBy && item.pledgedBy !== req.user._id
|
||||||
span.ugc=lang('WISHLIST_PLEDGED', item.pledgedBy)
|
if item.pledgedBy === '_CCUNKNOWN'
|
||||||
|
span.ugc=lang('WISHLIST_PLEDGED_GUEST')
|
||||||
|
else
|
||||||
|
span.ugc=lang('WISHLIST_PLEDGED', item.pledgedBy)
|
||||||
td(data-label='Delete Item')
|
td(data-label='Delete Item')
|
||||||
form.inline(
|
form.inline(
|
||||||
method='POST',
|
method='POST',
|
||||||
|
|
|
@ -2,7 +2,7 @@ extends layout.pug
|
||||||
|
|
||||||
block content
|
block content
|
||||||
ul.noStyle.noLeftMargin
|
ul.noStyle.noLeftMargin
|
||||||
if req.user._id !== 'Unknown'
|
if req.user._id !== '_CCUNKNOWN'
|
||||||
li
|
li
|
||||||
a(href=`${_CC.config.base}wishlist/${req.user._id}`)
|
a(href=`${_CC.config.base}wishlist/${req.user._id}`)
|
||||||
.box
|
.box
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -743,12 +743,12 @@
|
||||||
"resolved" "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz"
|
"resolved" "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz"
|
||||||
"version" "1.0.4"
|
"version" "1.0.4"
|
||||||
|
|
||||||
"cookie-parser@^1.4.3":
|
"cookie-parser@^1.4.3", "cookie-parser@^1.4.6":
|
||||||
"integrity" "sha512-f13bPUj/gG/5mDr+xLmSxxDsB9DQiTIfhJS/sqjrmfAWiAN+x2O4i/XguTL9yDZ+/IFDanJ+5x7hC4CXT9Tdzw=="
|
"integrity" "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA=="
|
||||||
"resolved" "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.5.tgz"
|
"resolved" "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz"
|
||||||
"version" "1.4.5"
|
"version" "1.4.6"
|
||||||
dependencies:
|
dependencies:
|
||||||
"cookie" "0.4.0"
|
"cookie" "0.4.1"
|
||||||
"cookie-signature" "1.0.6"
|
"cookie-signature" "1.0.6"
|
||||||
|
|
||||||
"cookie-signature@1.0.6":
|
"cookie-signature@1.0.6":
|
||||||
|
|
Loading…
Reference in a new issue