From b95560939908cd18c87fc23acb0f9bd652f8f88b Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 14 Feb 2022 10:29:58 +0000 Subject: [PATCH] Implemented User.changePassword --- lib/User.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/User.js b/lib/User.js index 6b17bc4..dc73b2f 100644 --- a/lib/User.js +++ b/lib/User.js @@ -66,8 +66,18 @@ class User { return await bcrypt.compare(password, this.password); } - changePassword(password) { + async changePassword(password) { + const newPassword = await User.hashPassword(password); + const conn = await new DatabaseConnectionPool(); + + const sql = ` + update ${this.type} + set password = ? + where ${this.type}Id = ?; + `; + + await conn.runQuery(sql, [ newPassword, this.id ]); } getPasswordReset() {