diff --git a/README.md b/README.md index 8733da5..2122dff 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ TRUST_PROXY=loopback BULMASWATCH=default # Set to false to disable update notices UPDATE_CHECK=true +# Set to false to disable the profile pictures feature +PFP=true ## Wishlist Settings # Set to true to not allow users to have their own lists. You may want this for a birthday or wedding. diff --git a/config/index.js b/config/index.js index 695306f..00b2029 100644 --- a/config/index.js +++ b/config/index.js @@ -13,5 +13,6 @@ module.exports = { wishlist: require('./wishlist'), base: (process.env.ROOT_PATH || '/').endsWith('/') ? (process.env.ROOT_PATH || '/') : `${process.env.ROOT_PATH}/`, 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' } diff --git a/routes/index.js b/routes/index.js index 141f495..6ef5870 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,6 +5,7 @@ const fs = require('fs/promises') module.exports = ({ db, config }) => { async function ensurePfp (username) { + if (!config.pfp) return const user = await db.get(username) if (user.pfp) return @@ -56,7 +57,7 @@ module.exports = ({ db, config }) => { router.use('/wishlist', require('./wishlist')(db)) router.use('/supported-sites', require('./supported-sites')()) - router.use('/profile', require('./profile')({ db, ensurePfp })) + router.use('/profile', require('./profile')({ db, config, ensurePfp })) router.use('/admin-settings', require('./adminSettings')({ db, ensurePfp })) diff --git a/routes/profile/index.js b/routes/profile/index.js index 36aff2d..0695b04 100644 --- a/routes/profile/index.js +++ b/routes/profile/index.js @@ -2,7 +2,7 @@ const verifyAuth = require('../../middlewares/verifyAuth') const bcrypt = require('bcrypt-nodejs') const express = require('express') -module.exports = ({ db, ensurePfp }) => { +module.exports = ({ db, config, ensurePfp }) => { const router = express.Router() router.get('/', verifyAuth(), async (req, res) => { @@ -11,10 +11,14 @@ module.exports = ({ db, ensurePfp }) => { }) router.post('/pfp', verifyAuth(), async (req, res) => { - req.user.pfp = req.body.image - await db.put(req.user) - if (!req.user.pfp) await ensurePfp(req.user._id) - req.flash('success', 'Saved profile picture!') + if (config.pfp) { + req.user.pfp = req.body.image + await db.put(req.user) + if (!req.user.pfp) await ensurePfp(req.user._id) + req.flash('success', 'Saved profile picture!') + } else { + req.flash('error', 'Profile pictures are disabled.') + } res.redirect(`${_CC.config.base}profile`) }) diff --git a/views/profile.pug b/views/profile.pug index 94f2a77..19892e3 100644 --- a/views/profile.pug +++ b/views/profile.pug @@ -1,29 +1,30 @@ extends layout.pug block content - h2 Profile - div(style='margin-top: 1em;') - .columns(style='margin-top: 1em;') - .column.is-narrow - .box - .columns - .column - figure.image.is-square(style='display: inline-block; width: 90%;') - img.is-rounded(src=req.user.pfp, style='object-fit: cover;') - .column.is-narrow - .column - span.is-size-3= req.user._id - br - br - form(action=`${_CC.config.base}profile/pfp`, method='POST') - label.label Image URL - .field.has-addons - .control - input.input(name='image', value=req.user.pfp) - .control - button.button.is-primary(type='submit') - span.icon - i.fas.fa-save + if config.pfp + h2 Profile + div(style='margin-top: 1em;') + .columns(style='margin-top: 1em;') + .column.is-narrow + .box + .columns + .column + figure.image.is-square(style='display: inline-block; width: 90%;') + img.is-rounded(src=req.user.pfp, style='object-fit: cover;') + .column.is-narrow + .column + span.is-size-3= req.user._id + br + br + form(action=`${_CC.config.base}profile/pfp`, method='POST') + label.label Image URL + .field.has-addons + .control + input.input(name='image', value=req.user.pfp) + .control + button.button.is-primary(type='submit') + span.icon + i.fas.fa-save h2 Security a.button.is-primary(href=`${_CC.config.base}profile/password`) span.icon diff --git a/views/wishlists.pug b/views/wishlists.pug index bae2129..ea4beb0 100644 --- a/views/wishlists.pug +++ b/views/wishlists.pug @@ -7,9 +7,10 @@ block content a(href=`${_CC.config.base}wishlist/${req.user._id}`) .box .columns - .column.is-1(style='overflow: hidden;') - figure.image.is-square.is-fullwidth.is-marginless(style='display: inline-block;') - img.is-rounded.is-fullwidth(src=req.user.pfp, style='object-fit: cover;') + if config.pfp + .column.is-1(style='overflow: hidden;') + figure.image.is-square.is-fullwidth.is-marginless(style='display: inline-block;') + img.is-rounded.is-fullwidth(src=req.user.pfp, style='object-fit: cover;') .column span=req.user._id span : ???/??? @@ -20,9 +21,10 @@ block content a(href=`${_CC.config.base}wishlist/${user.id}`) .box .columns - .column.is-1(style='overflow: hidden;') - figure.image.is-square.is-fullwidth.is-marginless(style='display: inline-block;') - img.is-rounded.is-fullwidth(src=user.doc.pfp, style='object-fit: cover;') + if config.pfp + .column.is-1(style='overflow: hidden;') + figure.image.is-square.is-fullwidth.is-marginless(style='display: inline-block;') + img.is-rounded.is-fullwidth(src=user.doc.pfp, style='object-fit: cover;') .column span= user.id span : #{totals(user.doc.wishlist).pledged}/#{user.doc.wishlist.length}