From 92b9d60c00432c58d6184f3683bdb14a0300a3c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Aug 2018 10:55:27 +0200 Subject: Add ability to delete our account --- server/middlewares/validators/users.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'server/middlewares/validators/users.ts') diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 8ca9763a1..3c207c81f 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -74,6 +74,19 @@ const usersRemoveValidator = [ } ] +const deleteMeValidator = [ + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + const user: UserModel = res.locals.oauth.token.User + if (user.username === 'root') { + return res.status(400) + .send({ error: 'You cannot delete your root account.' }) + .end() + } + + return next() + } +] + const usersUpdateValidator = [ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), body('email').optional().isEmail().withMessage('Should have a valid email attribute'), @@ -215,6 +228,7 @@ const usersResetPasswordValidator = [ export { usersAddValidator, + deleteMeValidator, usersRegisterValidator, usersRemoveValidator, usersUpdateValidator, -- cgit v1.2.3