({ token, hash, password })
| 485 | } |
| 486 | |
| 487 | async changePassword({ token, hash, password }) { |
| 488 | // decrypt the hash to get the user information |
| 489 | let user; |
| 490 | try { |
| 491 | user = JSON.parse(decrypt(hash)); |
| 492 | } catch (e) { |
| 493 | return new Promise((resolve, reject) => reject(e)); |
| 494 | } |
| 495 | |
| 496 | // check if the existing token is valid first |
| 497 | return this.findById(user.id) |
| 498 | .then(async (existingUser) => { |
| 499 | if (existingUser.passwordResetToken !== token) { |
| 500 | return new Promise((resolve, reject) => reject(new Error(401))); |
| 501 | } |
| 502 | |
| 503 | const bcryptHash = await bcrypt.hash(password, 10); |
| 504 | |
| 505 | const userUpdate = { |
| 506 | passwordResetToken: uuid(), |
| 507 | password: bcryptHash, |
| 508 | }; |
| 509 | |
| 510 | return this.update(user.id, userUpdate); |
| 511 | }) |
| 512 | .then(() => { |
| 513 | return new Promise((resolve) => resolve({ completed: true })); |
| 514 | }) |
| 515 | .catch((error) => { |
| 516 | return new Promise((resolve, reject) => reject(error)); |
| 517 | }); |
| 518 | } |
| 519 | |
| 520 | areThereAnyUsers() { |
| 521 | return db.User.findAll({ limit: 1 }) |
no test coverage detected