add reset password in cli

This commit is contained in:
LouisLam 2021-08-09 13:34:44 +08:00
parent 6f489e7e0f
commit d0aad3400c
6 changed files with 115 additions and 20 deletions

21
server/model/user.js Normal file
View file

@ -0,0 +1,21 @@
const { BeanModel } = require("redbean-node/dist/bean-model");
const passwordHash = require("../password-hash");
const { R } = require("redbean-node");
class User extends BeanModel {
/**
* Direct execute, no need R.store()
* @param newPassword
* @returns {Promise<void>}
*/
async resetPassword(newPassword) {
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
passwordHash.generate(newPassword),
this.id
]);
this.password = newPassword;
}
}
module.exports = User;