diff --git a/routes/adminSettings/index.js b/routes/adminSettings/index.js index 24c7408..4e43dc7 100644 --- a/routes/adminSettings/index.js +++ b/routes/adminSettings/index.js @@ -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) => { if (!req.user.admin) return res.redirect('/'); const doc = await db.get(req.params.userToRemove); diff --git a/views/admin-user-edit.pug b/views/admin-user-edit.pug index 4c48930..dace33f 100644 --- a/views/admin-user-edit.pug +++ b/views/admin-user-edit.pug @@ -31,17 +31,25 @@ block content input.button.is-rounded(type='submit', value='Generate New Link') .level-item a(href=signupLink, style='font-family: monospaced; word-break: break-all;')= signupLink - h2 Change Name - form(action=`${_CC.config.base}admin-settings/edit/rename/${user._id}`, method='POST') - .field - label.label Username - .control.has-icons-left - input.input(type='text', name='newUsername', placeholder=user._id, value=user._id) - span.icon.is-small.is-left - i.fas.fa-user - .field - .control - input.button.is-primary(type='submit' value='Change Username') + .columns + .column.is-narrow + h2 Change Name + form(action=`${_CC.config.base}admin-settings/edit/rename/${user._id}`, method='POST') + .field + label.label Username + .control.has-icons-left + input.input(type='text', name='newUsername', placeholder=user._id, value=user._id) + span.icon.is-small.is-left + i.fas.fa-user + .field + .control + 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 if user.pwToken - const resetLink = `${_CC.config.base}resetpw/${user.pwToken}`