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