2021-08-09 01:34:44 -04:00
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
const passwordHash = require("../password-hash");
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
|
|
|
|
class User extends BeanModel {
|
|
|
|
|
|
|
|
/**
|
2022-04-18 03:21:58 -04:00
|
|
|
*
|
|
|
|
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
|
|
|
|
* @param userID
|
2021-08-09 01:34:44 -04:00
|
|
|
* @param newPassword
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2022-04-18 03:21:58 -04:00
|
|
|
static async resetPassword(userID, newPassword) {
|
2021-08-09 01:34:44 -04:00
|
|
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
|
|
|
passwordHash.generate(newPassword),
|
2022-04-18 03:21:58 -04:00
|
|
|
userID
|
2021-08-09 01:34:44 -04:00
|
|
|
]);
|
2022-04-18 03:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param newPassword
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
async resetPassword(newPassword) {
|
|
|
|
await User.resetPassword(this.id, newPassword);
|
2021-08-09 01:34:44 -04:00
|
|
|
this.password = newPassword;
|
|
|
|
}
|
2022-04-18 03:21:58 -04:00
|
|
|
|
2021-08-09 01:34:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = User;
|