feat: Implement forgotPassword mutation

This commit is contained in:
Faruk AYDIN
2023-02-18 16:54:01 +01:00
parent e4021bf830
commit 90dcbadc52
7 changed files with 70 additions and 2 deletions

View File

@@ -5,12 +5,15 @@ import Flow from './flow';
import Step from './step';
import Execution from './execution';
import bcrypt from 'bcrypt';
import crypto from 'crypto';
class User extends Base {
id!: string;
email!: string;
password!: string;
role: string;
resetPasswordToken: string;
resetPasswordTokenSentAt: string;
connections?: Connection[];
flows?: Flow[];
steps?: Step[];
@@ -77,6 +80,13 @@ class User extends Base {
return bcrypt.compare(password, this.password);
}
async generateResetPasswordToken() {
const resetPasswordToken = crypto.randomBytes(64).toString('hex');
const resetPasswordTokenSentAt = new Date().toISOString();
await this.$query().patch({ resetPasswordToken, resetPasswordTokenSentAt });
}
async generateHash() {
this.password = await bcrypt.hash(this.password, 10);
}