1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-27 13:08:15 +09:00
MisskeyIO/src/server/api/endpoints/i/delete-account.ts

54 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-02-21 01:30:21 +09:00
import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import User from '../../../../models/user';
import define from '../../define';
import { createDeleteNotesJob, createDeleteDriveFilesJob } from '../../../../queue';
import Message from '../../../../models/messaging-message';
import Signin from '../../../../models/signin';
2019-02-21 01:30:21 +09:00
export const meta = {
requireCredential: true,
secure: true,
params: {
password: {
validator: $.str
},
}
};
export default define(meta, async (ps, user) => {
2019-02-21 01:30:21 +09:00
// Compare password
const same = await bcrypt.compare(ps.password, user.password);
if (!same) {
throw new Error('incorrect password');
2019-02-21 01:30:21 +09:00
}
await User.update({ _id: user._id }, {
$set: {
isDeleted: true,
token: null,
name: null,
description: null,
pinnedNoteIds: [],
password: null,
email: null,
twitter: null,
github: null,
discord: null,
profile: {},
fields: [],
clientSettings: {},
}
});
Message.remove({ userId: user._id });
Signin.remove({ userId: user._id });
2019-02-21 01:30:21 +09:00
createDeleteNotesJob(user);
createDeleteDriveFilesJob(user);
return;
});