diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-08 10:55:27 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-08 10:55:27 +0200 |
commit | 92b9d60c00432c58d6184f3683bdb14a0300a3c6 (patch) | |
tree | 4ef84e470e8289225c3987e48c458086b1883d67 /server/middlewares/validators | |
parent | a031ab0b9b2f06969f074622383a5c974666ba93 (diff) | |
download | PeerTube-92b9d60c00432c58d6184f3683bdb14a0300a3c6.tar.gz PeerTube-92b9d60c00432c58d6184f3683bdb14a0300a3c6.tar.zst PeerTube-92b9d60c00432c58d6184f3683bdb14a0300a3c6.zip |
Add ability to delete our account
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/users.ts | 14 |
1 files changed, 14 insertions, 0 deletions
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 = [ | |||
74 | } | 74 | } |
75 | ] | 75 | ] |
76 | 76 | ||
77 | const deleteMeValidator = [ | ||
78 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
79 | const user: UserModel = res.locals.oauth.token.User | ||
80 | if (user.username === 'root') { | ||
81 | return res.status(400) | ||
82 | .send({ error: 'You cannot delete your root account.' }) | ||
83 | .end() | ||
84 | } | ||
85 | |||
86 | return next() | ||
87 | } | ||
88 | ] | ||
89 | |||
77 | const usersUpdateValidator = [ | 90 | const usersUpdateValidator = [ |
78 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), | 91 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), |
79 | body('email').optional().isEmail().withMessage('Should have a valid email attribute'), | 92 | body('email').optional().isEmail().withMessage('Should have a valid email attribute'), |
@@ -215,6 +228,7 @@ const usersResetPasswordValidator = [ | |||
215 | 228 | ||
216 | export { | 229 | export { |
217 | usersAddValidator, | 230 | usersAddValidator, |
231 | deleteMeValidator, | ||
218 | usersRegisterValidator, | 232 | usersRegisterValidator, |
219 | usersRemoveValidator, | 233 | usersRemoveValidator, |
220 | usersUpdateValidator, | 234 | usersUpdateValidator, |