Renamed the password reset token creation class to better fit the scheme
ref #40
This commit is contained in:
parent
61aff5e629
commit
aef8485f59
|
@ -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<any> {
|
||||
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;
|
Loading…
Reference in New Issue