Merge alpha 0.0.5 to master #54

Merged
niggl merged 292 commits from dev into main 2020-12-23 17:05:35 +00:00
Showing only changes of commit aef8485f59 - Show all commits

View File

@ -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;