diff --git a/src/models/actions/ResetPassword.ts b/src/models/actions/CreateResetToken.ts similarity index 61% rename from src/models/actions/ResetPassword.ts rename to src/models/actions/CreateResetToken.ts index 186f4cb..0e32aad 100644 --- a/src/models/actions/ResetPassword.ts +++ b/src/models/actions/CreateResetToken.ts @@ -8,18 +8,16 @@ import { User } from '../entities/User'; /** * TODO: */ -export class ResetPassword { +export class CreateResetToken { /** - * The username of the user that want's to login. - * Either username or email have to be provided. + * The username of the user that wants to reset their password. */ @IsOptional() @IsString() username?: string; /** - * The email address of the user that want's to login. - * Either username or email have to be provided. + * The email address of the user that wants to reset their password. */ @IsOptional() @IsEmail() @@ -28,17 +26,20 @@ export class ResetPassword { /** - * Reset a password based on this. + * Create a password reset token based on this. */ public async toResetToken(): Promise { if (this.email === undefined && this.username === undefined) { throw new UsernameOrEmailNeededError(); } - const found_user = await getConnectionManager().get().getRepository(User).findOne({ where: [{ username: this.username }, { email: this.email }] }); + let found_user = await getConnectionManager().get().getRepository(User).findOne({ relations: ['groups', 'permissions', 'actions'], where: [{ username: this.username }, { email: this.email }] }); if (!found_user) { throw new UserNotFoundError(); } + found_user.refreshTokenCount = found_user.refreshTokenCount + 1; + await getConnectionManager().get().getRepository(User).save(found_user); + //Create the reset let access_token = JwtCreator.createReset(found_user); return access_token;