テーブル分割
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import define from '../../define';
|
||||
import { Users } from '../../../../models';
|
||||
import { UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@@ -20,8 +20,10 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.currentPassword, user.password);
|
||||
const same = await bcrypt.compare(ps.currentPassword, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
@@ -31,7 +33,7 @@ export default define(meta, async (ps, user) => {
|
||||
const salt = await bcrypt.genSalt(8);
|
||||
const hash = await bcrypt.hash(ps.newPassword, salt);
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
password: hash
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user