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:
|
* TODO:
|
||||||
*/
|
*/
|
||||||
export class ResetPassword {
|
export class CreateResetToken {
|
||||||
/**
|
/**
|
||||||
* The username of the user that want's to login.
|
* The username of the user that wants to reset their password.
|
||||||
* Either username or email have to be provided.
|
|
||||||
*/
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
username?: string;
|
username?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The email address of the user that want's to login.
|
* The email address of the user that wants to reset their password.
|
||||||
* Either username or email have to be provided.
|
|
||||||
*/
|
*/
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEmail()
|
@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> {
|
public async toResetToken(): Promise<any> {
|
||||||
if (this.email === undefined && this.username === undefined) {
|
if (this.email === undefined && this.username === undefined) {
|
||||||
throw new UsernameOrEmailNeededError();
|
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) {
|
if (!found_user) {
|
||||||
throw new UserNotFoundError();
|
throw new UserNotFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
found_user.refreshTokenCount = found_user.refreshTokenCount + 1;
|
||||||
|
await getConnectionManager().get().getRepository(User).save(found_user);
|
||||||
|
|
||||||
//Create the reset
|
//Create the reset
|
||||||
let access_token = JwtCreator.createReset(found_user);
|
let access_token = JwtCreator.createReset(found_user);
|
||||||
return access_token;
|
return access_token;
|
Loading…
x
Reference in New Issue
Block a user