monkeeShark/src/api/endpoints/i/2fa/unregister.ts
Akihiko Odaki 19b9cb105d Introduce account document to user document
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.
2018-03-26 14:07:16 +09:00

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();
});