2021-08-09 06:34:44 +01: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-21 18:30:04 +01:00
|
|
|
* Reset user password
|
2022-04-18 08:21:58 +01:00
|
|
|
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
|
2022-04-21 18:30:04 +01:00
|
|
|
* @param {number} userID ID of user to update
|
2023-08-11 08:46:41 +01:00
|
|
|
* @param {string} newPassword Users new password
|
2021-08-09 06:34:44 +01:00
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2022-04-18 08:21:58 +01:00
|
|
|
static async resetPassword(userID, newPassword) {
|
2021-08-09 06:34:44 +01:00
|
|
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
|
|
|
passwordHash.generate(newPassword),
|
2022-04-18 08:21:58 +01:00
|
|
|
userID
|
2021-08-09 06:34:44 +01:00
|
|
|
]);
|
2022-04-18 08:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-21 18:30:04 +01:00
|
|
|
* Reset this users password
|
2023-08-11 08:46:41 +01:00
|
|
|
* @param {string} newPassword Users new password
|
2022-04-18 08:21:58 +01:00
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
async resetPassword(newPassword) {
|
|
|
|
await User.resetPassword(this.id, newPassword);
|
2021-08-09 06:34:44 +01:00
|
|
|
this.password = newPassword;
|
|
|
|
}
|
2022-04-18 08:21:58 +01:00
|
|
|
|
2021-08-09 06:34:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = User;
|