mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 07:04:20 -05:00
refactor: move error messages from controller to service
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
f672c5179f
commit
4500caf882
2 changed files with 11 additions and 21 deletions
|
@ -75,25 +75,15 @@ export class AuthController {
|
|||
@RequestUser() user: User,
|
||||
@Body() changePasswordDto: UpdatePasswordDto,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await this.identityService.checkLocalPassword(
|
||||
user,
|
||||
changePasswordDto.currentPassword,
|
||||
);
|
||||
await this.identityService.updateLocalPassword(
|
||||
user,
|
||||
changePasswordDto.newPassword,
|
||||
);
|
||||
return;
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidCredentialsError) {
|
||||
throw new UnauthorizedException('Password is not correct');
|
||||
}
|
||||
if (e instanceof NoLocalIdentityError) {
|
||||
throw new BadRequestException('User has no local identity.');
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
await this.identityService.checkLocalPassword(
|
||||
user,
|
||||
changePasswordDto.currentPassword,
|
||||
);
|
||||
await this.identityService.updateLocalPassword(
|
||||
user,
|
||||
changePasswordDto.newPassword,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@UseGuards(LoginEnabledGuard, LocalAuthGuard)
|
||||
|
|
|
@ -85,14 +85,14 @@ export class IdentityService {
|
|||
`The user with the username ${user.username} does not have a internal identity.`,
|
||||
'checkLocalPassword',
|
||||
);
|
||||
throw new NoLocalIdentityError();
|
||||
throw new NoLocalIdentityError('This user has no internal identity.');
|
||||
}
|
||||
if (!(await checkPassword(password, internalIdentity.passwordHash ?? ''))) {
|
||||
this.logger.debug(
|
||||
`Password check for ${user.username} did not succeed.`,
|
||||
'checkLocalPassword',
|
||||
);
|
||||
throw new InvalidCredentialsError();
|
||||
throw new InvalidCredentialsError('Password is not correct');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue