19b9cb105d
An account document is attached to a user document if an account of the user is on the server. It may be missing if the user is on a remote server.
28 lines
641 B
TypeScript
28 lines
641 B
TypeScript
/**
|
|
* Module dependencies
|
|
*/
|
|
import $ from 'cafy';
|
|
import * as bcrypt from 'bcryptjs';
|
|
import User from '../../../models/user';
|
|
|
|
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|
// Get 'password' parameter
|
|
const [password, passwordErr] = $(params.password).string().$;
|
|
if (passwordErr) return rej('invalid password param');
|
|
|
|
// Compare password
|
|
const same = await bcrypt.compare(password, user.account.password);
|
|
|
|
if (!same) {
|
|
return rej('incorrect password');
|
|
}
|
|
|
|
await User.update(user._id, {
|
|
$set: {
|
|
'account.two_factor_secret': null,
|
|
'account.two_factor_enabled': false
|
|
}
|
|
});
|
|
|
|
res();
|
|
});
|