Resolve #2017
This commit is contained in:
parent
7174a55846
commit
3409a51cca
10 changed files with 253 additions and 29 deletions
49
src/server/api/endpoints/i/delete-account.ts
Normal file
49
src/server/api/endpoints/i/delete-account.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import User from '../../../../models/user';
|
||||
import define from '../../define';
|
||||
import { createDeleteNotesJob, createDeleteDriveFilesJob } from '../../../../queue';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
|
||||
secure: true,
|
||||
|
||||
params: {
|
||||
password: {
|
||||
validator: $.str
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.password, user.password);
|
||||
|
||||
if (!same) {
|
||||
return rej('incorrect password');
|
||||
}
|
||||
|
||||
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: {},
|
||||
}
|
||||
});
|
||||
|
||||
createDeleteNotesJob(user);
|
||||
createDeleteDriveFilesJob(user);
|
||||
|
||||
res();
|
||||
}));
|
Loading…
Add table
Add a link
Reference in a new issue