impersonation

This commit is contained in:
Wingy 2020-11-03 20:25:20 -05:00
parent cec98a5016
commit 2707ac5773
2 changed files with 31 additions and 11 deletions

View file

@ -118,6 +118,18 @@ module.exports = (db) => {
} }
}) })
router.post('/edit/impersonate/:userToEdit', verifyAuth(), async (req, res) => {
if (!req.user.admin) return res.redirect('/');
req.login({ _id: req.params.userToEdit }, err => {
if (err) {
req.flash('error', err.message)
return res.redirect(`/admin-settings/edit/${req.params.userToEdit}`)
}
req.flash('success', `You are now ${req.params.userToEdit}.`)
res.redirect('/')
})
});
router.post('/edit/remove/:userToRemove', verifyAuth(), async (req, res) => { router.post('/edit/remove/:userToRemove', verifyAuth(), async (req, res) => {
if (!req.user.admin) return res.redirect('/'); if (!req.user.admin) return res.redirect('/');
const doc = await db.get(req.params.userToRemove); const doc = await db.get(req.params.userToRemove);

View file

@ -31,6 +31,8 @@ block content
input.button.is-rounded(type='submit', value='Generate New Link') input.button.is-rounded(type='submit', value='Generate New Link')
.level-item .level-item
a(href=signupLink, style='font-family: monospaced; word-break: break-all;')= signupLink a(href=signupLink, style='font-family: monospaced; word-break: break-all;')= signupLink
.columns
.column.is-narrow
h2 Change Name h2 Change Name
form(action=`${_CC.config.base}admin-settings/edit/rename/${user._id}`, method='POST') form(action=`${_CC.config.base}admin-settings/edit/rename/${user._id}`, method='POST')
.field .field
@ -42,6 +44,12 @@ block content
.field .field
.control .control
input.button.is-primary(type='submit' value='Change Username') input.button.is-primary(type='submit' value='Change Username')
.column.is-narrow
h2 Impersonate
form(action=`${_CC.config.base}admin-settings/edit/impersonate/${user._id}`, method='POST')
.field
.control
input.input.button.is-warning(type='submit', value=`Log in as ${user._id}`, style='margin-top: 1em;')
h2(style='margin-bottom: 1em;') Reset Password h2(style='margin-bottom: 1em;') Reset Password
if user.pwToken if user.pwToken
- const resetLink = `${_CC.config.base}resetpw/${user.pwToken}` - const resetLink = `${_CC.config.base}resetpw/${user.pwToken}`