localization support
This commit is contained in:
parent
f99d6f88c3
commit
d91128274b
29 changed files with 396 additions and 194 deletions
|
@ -18,7 +18,7 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
if (!req.user.admin) return res.redirect('/')
|
||||
db.allDocs({ include_docs: true })
|
||||
.then(docs => {
|
||||
res.render('adminSettings', { title: 'Admin Settings', users: docs.rows })
|
||||
res.render('adminSettings', { title: _CC.lang('ADMIN_SETTINGS_HEADER'), users: docs.rows })
|
||||
})
|
||||
.catch(err => { throw err })
|
||||
})
|
||||
|
@ -75,11 +75,11 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
router.post('/edit/rename/:userToRename', verifyAuth(), async (req, res) => {
|
||||
if (!req.user.admin && req.user._id !== req.params.userToRename) return res.redirect('/')
|
||||
if (!req.body.newUsername) {
|
||||
req.flash('error', 'No username provided')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_NO_USERNAME_PROVIDED'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToRename}`)
|
||||
}
|
||||
if (req.body.newUsername === req.params.userToRename) {
|
||||
req.flash('error', 'Username is same as new username.')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_SAME_NAME'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToRename}`)
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
await db.bulkDocs(usersBulk)
|
||||
await db.remove(await db.get(oldName))
|
||||
|
||||
await req.flash('success', 'Renamed user!')
|
||||
req.flash('success', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_RENAMED_USER'))
|
||||
return res.redirect(`/wishlist/${newName}`)
|
||||
} catch (error) {
|
||||
console.log(error, error.stack)
|
||||
|
@ -125,7 +125,7 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
req.flash('error', err.message)
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToEdit}`)
|
||||
}
|
||||
req.flash('success', `You are now ${req.params.userToEdit}.`)
|
||||
req.flash('success', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_IMPERSONATE_SUCCESS', req.params.userToEdit))
|
||||
res.redirect('/')
|
||||
})
|
||||
})
|
||||
|
@ -134,43 +134,43 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
if (!req.user.admin) return res.redirect('/')
|
||||
const user = await db.get(req.params.userToPromote)
|
||||
if (!user) {
|
||||
req.flash('error', 'User not found.')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_PROMOTE_DEMOTE_NOT_FOUND'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToPromote}`)
|
||||
}
|
||||
if (user.admin) {
|
||||
req.flash('error', 'user is already admin')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_PROMOTE_ALREADY_ADMIN'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToPromote}`)
|
||||
}
|
||||
|
||||
user.admin = true
|
||||
await db.put(user)
|
||||
|
||||
req.flash('success', `${user._id} is now an admin.`)
|
||||
req.flash('success', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_PROMOTE_SUCCESS', user._id))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToPromote}`)
|
||||
})
|
||||
|
||||
router.post('/edit/demote/:userToDemote', verifyAuth(), async (req, res) => {
|
||||
if (!req.user.admin) return res.redirect('/')
|
||||
if (req.user._id === req.params.userToDemote) {
|
||||
req.flash('error', 'You cannot demote yourself.')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_DEMOTE_SELF'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToDemote}`)
|
||||
}
|
||||
|
||||
const user = await db.get(req.params.userToDemote)
|
||||
|
||||
if (!user) {
|
||||
req.flash('error', 'User not found.')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_PROMOTE_DEMOTE_NOT_FOUND'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToDemote}`)
|
||||
}
|
||||
if (!user.admin) {
|
||||
req.flash('error', 'user is not an admin')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_DEMOTE_NOT_ADMIN'))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToDemote}`)
|
||||
}
|
||||
|
||||
user.admin = false
|
||||
await db.put(user)
|
||||
|
||||
req.flash('success', `${user._id} is no longer an admin.`)
|
||||
req.flash('success', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_DEMOTE_SUCCESS', user._id))
|
||||
return res.redirect(`/admin-settings/edit/${req.params.userToDemote}`)
|
||||
})
|
||||
|
||||
|
@ -178,7 +178,7 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
if (!req.user.admin) return res.redirect('/')
|
||||
const doc = await db.get(req.params.userToRemove)
|
||||
if (doc.admin) {
|
||||
req.flash('error', 'Failed to remove: user is admin.')
|
||||
req.flash('error', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_DELETE_FAIL_ADMIN'))
|
||||
return res.redirect('/admin-settings')
|
||||
}
|
||||
await db.remove(doc)
|
||||
|
@ -192,7 +192,7 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
req.flash('success', `Successfully removed user ${req.params.userToRemove}`)
|
||||
req.flash('success', _CC.lang('ADMIN_SETTINGS_USERS_EDIT_DELETE_SUCCESS', req.params.userToRemove))
|
||||
res.redirect('/admin-settings')
|
||||
})
|
||||
|
||||
|
@ -208,7 +208,7 @@ module.exports = ({ db, ensurePfp }) => {
|
|||
row.doc.wishlist = []
|
||||
await db.put(row.doc)
|
||||
}
|
||||
req.flash('success', 'Cleared all wishlists.')
|
||||
req.flash('success', _CC.lang('ADMIN_SETTINGS_CLEARDB_SUCCESS'))
|
||||
res.redirect('/admin-settings')
|
||||
})
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module.exports = (db) => {
|
|||
req.flash('error', err.message)
|
||||
return res.redirect('/')
|
||||
}
|
||||
req.flash('success', `Welcome to ${_CC.config.siteTitle}!`)
|
||||
req.flash('success', _CC.lang('CONFIRM_ACCOUNT_SUCCESS'))
|
||||
res.redirect('/')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -7,7 +7,7 @@ module.exports = ({ db, config, ensurePfp }) => {
|
|||
|
||||
router.get('/', verifyAuth(), async (req, res) => {
|
||||
await ensurePfp(req.user._id)
|
||||
res.render('profile', { title: `Profile Settings - ${req.user._id}` })
|
||||
res.render('profile', { title: _CC.lang('PROFILE_TITLE', req.user._id) })
|
||||
})
|
||||
|
||||
router.post('/pfp', verifyAuth(), async (req, res) => {
|
||||
|
@ -15,24 +15,24 @@ module.exports = ({ db, config, ensurePfp }) => {
|
|||
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!')
|
||||
req.flash('success', _CC.lang('PROFILE_SAVE_PFP_SUCCESS'))
|
||||
} else {
|
||||
req.flash('error', 'Profile pictures are disabled.')
|
||||
req.flash('error', _CC.lang('PROFILE_SAVE_PFP_DISABLED'))
|
||||
}
|
||||
res.redirect(`${_CC.config.base}profile`)
|
||||
})
|
||||
|
||||
router.get('/password', verifyAuth(), async (req, res) => {
|
||||
await ensurePfp(req.user._id)
|
||||
res.render('profile-password', { title: `Profile Settings - Password - ${req.user._id}` })
|
||||
res.render('profile-password', { title: _CC.lang('PROFILE_PASSWORD_TITLE', req.user._id) })
|
||||
})
|
||||
router.post('/password', verifyAuth(), (req, res) => {
|
||||
if (!req.body.oldPassword) {
|
||||
req.flash('error', 'Old Password is required')
|
||||
req.flash('error', _CC.lang('PROFILE_PASSWORD_REQUIRED_OLD'))
|
||||
return res.redirect('/profile/password')
|
||||
}
|
||||
if (!req.body.newPassword) {
|
||||
req.flash('error', 'New Password is required')
|
||||
req.flash('error', _CC.lang('PROFILE_PASSWORD_REQUIRED_NEW'))
|
||||
return res.redirect('/profile/password')
|
||||
}
|
||||
bcrypt.compare(req.body.oldPassword, req.user.password, (err, correct) => {
|
||||
|
@ -45,7 +45,7 @@ module.exports = ({ db, config, ensurePfp }) => {
|
|||
doc.password = hash
|
||||
db.put(doc)
|
||||
.then(() => {
|
||||
req.flash('success', 'Changes saved successfully!')
|
||||
req.flash('success', _CC.lang('PROFILE_PASSWORD_SUCCESS'))
|
||||
res.redirect('/profile/password')
|
||||
})
|
||||
.catch(err => { throw err })
|
||||
|
@ -53,7 +53,7 @@ module.exports = ({ db, config, ensurePfp }) => {
|
|||
.catch(err => { throw err })
|
||||
})
|
||||
} else {
|
||||
req.flash('error', 'Incorrect old password')
|
||||
req.flash('error', _CC.lang('PROFILE_PASSWORD_OLD_MISMATCH'))
|
||||
res.redirect('/profile/password')
|
||||
}
|
||||
})
|
||||
|
|
|
@ -34,7 +34,7 @@ module.exports = (db) => {
|
|||
req.flash('error', err.message)
|
||||
return res.redirect('/')
|
||||
}
|
||||
req.flash('success', `Welcome to ${_CC.config.siteTitle}!`)
|
||||
req.flash('success', _CC.lang('RESET_PASSWORD_SUCCESS'))
|
||||
res.redirect('/')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = (db) => {
|
|||
async (req, res) => {
|
||||
const dbInfo = await db.info()
|
||||
if (dbInfo.doc_count === 0) {
|
||||
res.render('setup', { title: 'Setup' })
|
||||
res.render('setup', { title: _CC.lang('SETUP_HEADER') })
|
||||
} else {
|
||||
res.redirect('/')
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ module.exports = () => {
|
|||
const router = express.Router()
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
res.render('supported-sites', { title: 'Supported Sites' })
|
||||
res.render('supported-sites', { title: _CC.lang('SUPPORTED_SITES_HEADER') })
|
||||
})
|
||||
|
||||
return router
|
||||
|
|
|
@ -44,7 +44,7 @@ module.exports = (db) => {
|
|||
if (row.doc.admin) return res.redirect(`/wishlist/${row.doc._id}`)
|
||||
}
|
||||
}
|
||||
res.render('wishlists', { title: 'Wishlists', users: docs.rows, totals })
|
||||
res.render('wishlists', { title: _CC.lang('WISHLISTS_TITLE'), users: docs.rows, totals })
|
||||
})
|
||||
|
||||
router.get('/:user', publicRoute(), async (req, res) => {
|
||||
|
@ -66,7 +66,8 @@ module.exports = (db) => {
|
|||
if (global._CC.config.wishlist.note.markdown) item.note = DOMPurify.sanitize(marked(item.note))
|
||||
}
|
||||
res.render('wishlist', {
|
||||
title: `Wishlist - ${dbUser._id}`,
|
||||
title: _CC.lang('WISHLIST_TITLE', dbUser._id),
|
||||
name: dbUser._id,
|
||||
wishlist: [
|
||||
...dbUser.wishlist.filter(item => item.addedBy === req.params.user),
|
||||
...dbUser.wishlist.filter(item => item.addedBy !== req.params.user)
|
||||
|
@ -82,7 +83,7 @@ module.exports = (db) => {
|
|||
|
||||
router.post('/:user', verifyAuth(), async (req, res) => {
|
||||
if (!req.body.itemUrlOrName) {
|
||||
req.flash('error', 'Item URL or Name is required')
|
||||
req.flash('error', _CC.lang('WISHLIST_URL_REQUIRED'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
const potentialUrl = req.body.itemUrlOrName.split(' ').pop()
|
||||
|
@ -108,7 +109,7 @@ module.exports = (db) => {
|
|||
try {
|
||||
await db.put(doc)
|
||||
} catch {
|
||||
req.flash('error', 'Items are being added too quickly. Please try again.')
|
||||
req.flash('error', _CC.lang('WISHLIST_CONFLICT'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
req.flash(
|
||||
|
@ -128,12 +129,12 @@ module.exports = (db) => {
|
|||
for (let j = 0; j < docs.rows[i].doc.wishlist.length; j++) {
|
||||
if (docs.rows[i].doc.wishlist[j].id === req.params.itemId) {
|
||||
if (docs.rows[i].doc.wishlist[j].pledgedBy !== undefined) {
|
||||
req.flash('error', 'Item already pledged for')
|
||||
req.flash('error', _CC.lang('WISHLIST_PLEDGE_DUPLICATE'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
docs.rows[i].doc.wishlist[j].pledgedBy = req.user._id
|
||||
await db.put(docs.rows[i].doc)
|
||||
req.flash('success', 'Successfully pledged for item!')
|
||||
req.flash('success', _CC.lang('WISHLIST_PLEDGE_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
}
|
||||
|
@ -145,24 +146,24 @@ module.exports = (db) => {
|
|||
for (let j = 0; j < docs.rows[i].doc.wishlist.length; j++) {
|
||||
if (docs.rows[i].doc.wishlist[j].id === req.params.itemId) {
|
||||
if (docs.rows[i].doc.wishlist[j].pledgedBy !== req.user._id) {
|
||||
req.flash('error', 'You did not pledge for this')
|
||||
req.flash('error', _CC.lang('WISHLIST_UNPLEDGE_GUARD'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
docs.rows[i].doc.wishlist[j].pledgedBy = undefined
|
||||
if (docs.rows[i].doc.wishlist[j].addedBy === req.user._id) docs.rows[i].doc.wishlist.splice(j, 1)
|
||||
await db.put(docs.rows[i].doc)
|
||||
req.flash('success', 'Successfully unpledged for item')
|
||||
req.flash('success', _CC.lang('WISHLIST_UNPLEDGE_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
req.flash('error', 'Failed to find item')
|
||||
req.flash('error', _CC.lang('WISHLIST_UNPLEDGE_MISSING'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
})
|
||||
|
||||
router.post('/:user/remove/:itemId', verifyAuth(), async (req, res) => {
|
||||
if (req.user._id !== req.params.user) {
|
||||
req.flash('error', 'Not correct user')
|
||||
req.flash('error', _CC.lang('WISHLIST_REMOVE_GUARD'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
const doc = await db.get(req.user._id)
|
||||
|
@ -170,17 +171,17 @@ module.exports = (db) => {
|
|||
if (doc.wishlist[i].id === req.params.itemId) {
|
||||
doc.wishlist.splice(i, 1)
|
||||
await db.put(doc)
|
||||
req.flash('success', 'Successfully removed from wishlist')
|
||||
req.flash('success', _CC.lang('WISHLIST_REMOVE_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
}
|
||||
req.flash('error', 'Failed to find item')
|
||||
req.flash('error', _CC.lang('WISHLIST_REMOVE_MISSING'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
})
|
||||
|
||||
router.post('/:user/move/:direction/:itemId', verifyAuth(), async (req, res) => {
|
||||
if (req.user._id !== req.params.user) {
|
||||
req.flash('error', 'Not correct user')
|
||||
req.flash('error', _CC.lang('WISHLIST_MOVE_GUARD'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
const doc = await db.get(req.user._id)
|
||||
|
@ -197,7 +198,7 @@ module.exports = (db) => {
|
|||
})
|
||||
const moveToIndex = wishlist.findIndex(wish => (wishlist.indexOf(wish) > moveFromIndex && wish.addedBy === req.user._id))
|
||||
if (moveToIndex < 0 || moveToIndex > wishlist.length) {
|
||||
req.flash('error', 'Invalid move')
|
||||
req.flash('error', _CC.lang('WISHLIST_MOVE_INVALID'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
[wishlist[moveFromIndex], wishlist[moveToIndex]] = [wishlist[moveToIndex], wishlist[moveFromIndex]]
|
||||
|
@ -206,7 +207,7 @@ module.exports = (db) => {
|
|||
|
||||
doc.wishlist = wishlist
|
||||
await db.put(doc)
|
||||
req.flash('success', 'Successfully moved item!')
|
||||
req.flash('success', _CC.lang('WISHLIST_MOVE_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
})
|
||||
|
||||
|
@ -222,14 +223,14 @@ module.exports = (db) => {
|
|||
const wishlistItem = wishlist[i]
|
||||
if (wishlistItem.id !== req.params.id) continue
|
||||
if (req.user._id !== req.params.user && req.user._id !== wishlistItem.addedBy) {
|
||||
req.flash('error', 'Invalid user')
|
||||
req.flash('error', _CC.lang('NOTE_GUARD'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
for (const type of [
|
||||
'name', 'note', 'url', 'price', 'image'
|
||||
]) {
|
||||
if (!Object.prototype.hasOwnProperty.call(req.body, type)) {
|
||||
req.flash('error', `Missing property ${type}`)
|
||||
req.flash('error', _CC.lang('NOTE_MISSING_PROP', type))
|
||||
return res.redirect(`/wishlist/${req.params.user}/note/${req.params.id}`)
|
||||
}
|
||||
wishlistItem[type] = req.body[type]
|
||||
|
@ -238,7 +239,7 @@ module.exports = (db) => {
|
|||
}
|
||||
doc.wishlist = wishlist
|
||||
await db.put(doc)
|
||||
req.flash('success', 'Successfully saved note!')
|
||||
req.flash('success', _CC.lang('NOTE_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
})
|
||||
router.post('/:user/refresh/:id', verifyAuth(), async (req, res) => {
|
||||
|
@ -248,12 +249,12 @@ module.exports = (db) => {
|
|||
const wishlistItem = wishlist[i]
|
||||
if (wishlistItem.id !== req.params.id) continue
|
||||
if (req.user._id !== req.params.user && req.user._id !== wishlistItem.addedBy) {
|
||||
req.flash('error', 'Invalid user')
|
||||
req.flash('error', _CC.lang('WISHLIST_REFRESH_GUARD'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
|
||||
if (!wishlistItem.url) {
|
||||
req.flash('error', 'Item has no URL.')
|
||||
req.flash('error', _CC.lang('WISHLIST_REFRESH_NO_URL'))
|
||||
return res.redirect(`/wishlist/${req.params.user}/note/${req.params.id}`)
|
||||
}
|
||||
|
||||
|
@ -266,7 +267,7 @@ module.exports = (db) => {
|
|||
}
|
||||
doc.wishlist = wishlist
|
||||
await db.put(doc)
|
||||
req.flash('success', 'Successfully refreshed data!')
|
||||
req.flash('success', _CC.lang('WISHLIST_REFRESH_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}/note/${req.params.id}`)
|
||||
})
|
||||
router.post('/:user/note/remove/:id', verifyAuth(), async (req, res) => {
|
||||
|
@ -276,20 +277,20 @@ module.exports = (db) => {
|
|||
const wishlistItem = wishlist[i]
|
||||
if (wishlistItem.id !== req.params.id) continue
|
||||
if (req.user._id !== req.params.user && req.user._id !== wishlistItem.addedBy) {
|
||||
req.flash('error', 'Invalid user')
|
||||
req.flash('error', _CC.lang('NOTE_REMOVE_GUARD'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
if (wishlistItem.note) {
|
||||
wishlistItem.note = undefined
|
||||
wishlist[i] = wishlistItem
|
||||
} else {
|
||||
req.flash('error', 'Has no note')
|
||||
req.flash('error', _CC.lang('NOTE_REMOVE_MISSING'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
}
|
||||
}
|
||||
doc.wishlist = wishlist
|
||||
await db.put(doc)
|
||||
req.flash('success', 'Successfully removed note')
|
||||
req.flash('success', _CC.lang('NOTE_REMOVE_SUCCESS'))
|
||||
return res.redirect(`/wishlist/${req.params.user}`)
|
||||
})
|
||||
return router
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue