Fix account deletion.

This commit is contained in:
Jonathan Cremin 2019-07-21 19:37:20 +00:00
parent 5a7e695e53
commit 971d454e2c
9 changed files with 76 additions and 13 deletions

View file

@ -63,6 +63,7 @@ router.get('/user/token', auth, user.token);
router.get('/token', auth, user.token);
router.get('/user/transaction', auth, user.transaction);
router.post('/user/settings', auth, user.settings);
router.post('/user/delete', auth, user.deleteUser);
router.post('/user/pro', auth, pro.create);
router.delete('/user/pro', auth, pro.cancel);
router.get('/file', auth, file.list);

View file

@ -64,6 +64,24 @@ export async function settings(ctx) {
ctx.body = {};
}
export async function deleteUser(ctx) {
ctx.assert(
ctx.request.body, 400,
'{"error": {"message": "Current Password required to update account.", "code": 612}}',
);
ctx.assert(
ctx.request.body.current_password, 400,
'{"error": {"message": "Current Password required to update account.", "code": 612}}',
);
const user = await models.user.findByPk(ctx.user.id);
ctx.assert(
await passwords.match(ctx.request.body.current_password, user.password), 400,
'{"error": {"message": "Incorrect password", "code": 606}}',
);
await user.destroy();
ctx.body = '{"action":"logout", "message": "Account deleted"}';
}
export async function events(ctx) {
const pubsub = redis.createClient(redisUrl);
pubsub.on('message', (channel, message) => {