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/controllers/api | |
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/controllers/api')
-rw-r--r-- | server/controllers/api/users.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 36bf0e0fe..3d2586c3a 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -30,6 +30,7 @@ import { | |||
30 | usersVideoRatingValidator | 30 | usersVideoRatingValidator |
31 | } from '../../middlewares' | 31 | } from '../../middlewares' |
32 | import { | 32 | import { |
33 | deleteMeValidator, | ||
33 | usersAskResetPasswordValidator, | 34 | usersAskResetPasswordValidator, |
34 | usersResetPasswordValidator, | 35 | usersResetPasswordValidator, |
35 | videoImportsSortValidator, | 36 | videoImportsSortValidator, |
@@ -62,6 +63,11 @@ usersRouter.get('/me', | |||
62 | authenticate, | 63 | authenticate, |
63 | asyncMiddleware(getUserInformation) | 64 | asyncMiddleware(getUserInformation) |
64 | ) | 65 | ) |
66 | usersRouter.delete('/me', | ||
67 | authenticate, | ||
68 | asyncMiddleware(deleteMeValidator), | ||
69 | asyncMiddleware(deleteMe) | ||
70 | ) | ||
65 | 71 | ||
66 | usersRouter.get('/me/video-quota-used', | 72 | usersRouter.get('/me/video-quota-used', |
67 | authenticate, | 73 | authenticate, |
@@ -296,8 +302,18 @@ async function listUsers (req: express.Request, res: express.Response, next: exp | |||
296 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 302 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
297 | } | 303 | } |
298 | 304 | ||
305 | async function deleteMe (req: express.Request, res: express.Response) { | ||
306 | const user: UserModel = res.locals.oauth.token.User | ||
307 | |||
308 | await user.destroy() | ||
309 | |||
310 | auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) | ||
311 | |||
312 | return res.sendStatus(204) | ||
313 | } | ||
314 | |||
299 | async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 315 | async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) { |
300 | const user = await UserModel.loadById(req.params.id) | 316 | const user: UserModel = res.locals.user |
301 | 317 | ||
302 | await user.destroy() | 318 | await user.destroy() |
303 | 319 | ||