add some user delete functionalty
Build Images and Deploy / Update-PROD-Stack (push) Successful in 29s
Build Images and Deploy / Update-PROD-Stack (push) Successful in 29s
This commit is contained in:
@@ -136,6 +136,22 @@ router.post('/player/:username/password', requireAuth, (req, res) => {
|
||||
res.redirect(`/player/${user.username}`);
|
||||
});
|
||||
|
||||
// ─── Delete own account ───────────────────────────────────
|
||||
router.post('/player/:username/delete', requireAuth, (req, res) => {
|
||||
const user = Users.findByUsername(req.params.username);
|
||||
if (!user || user.id !== req.session.userId) {
|
||||
return res.status(403).render('error', { title: 'Forbidden', message: 'You can only delete your own account.' });
|
||||
}
|
||||
if (user.is_admin) {
|
||||
req.session.flash = { type: 'danger', message: 'Admin accounts cannot be deleted.' };
|
||||
return res.redirect(`/player/${user.username}`);
|
||||
}
|
||||
|
||||
Users.deleteUser(user.id);
|
||||
req.session.destroy();
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
// ─── Browse all hunts ─────────────────────────────────────
|
||||
router.get('/hunts', (req, res) => {
|
||||
const allHunts = Hunts.getAll();
|
||||
|
||||
Reference in New Issue
Block a user