mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 12:34:23 -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,7 +75,6 @@ export class AuthController {
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Body() changePasswordDto: UpdatePasswordDto,
|
@Body() changePasswordDto: UpdatePasswordDto,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
|
||||||
await this.identityService.checkLocalPassword(
|
await this.identityService.checkLocalPassword(
|
||||||
user,
|
user,
|
||||||
changePasswordDto.currentPassword,
|
changePasswordDto.currentPassword,
|
||||||
|
@ -85,15 +84,6 @@ export class AuthController {
|
||||||
changePasswordDto.newPassword,
|
changePasswordDto.newPassword,
|
||||||
);
|
);
|
||||||
return;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(LoginEnabledGuard, LocalAuthGuard)
|
@UseGuards(LoginEnabledGuard, LocalAuthGuard)
|
||||||
|
|
|
@ -85,14 +85,14 @@ export class IdentityService {
|
||||||
`The user with the username ${user.username} does not have a internal identity.`,
|
`The user with the username ${user.username} does not have a internal identity.`,
|
||||||
'checkLocalPassword',
|
'checkLocalPassword',
|
||||||
);
|
);
|
||||||
throw new NoLocalIdentityError();
|
throw new NoLocalIdentityError('This user has no internal identity.');
|
||||||
}
|
}
|
||||||
if (!(await checkPassword(password, internalIdentity.passwordHash ?? ''))) {
|
if (!(await checkPassword(password, internalIdentity.passwordHash ?? ''))) {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Password check for ${user.username} did not succeed.`,
|
`Password check for ${user.username} did not succeed.`,
|
||||||
'checkLocalPassword',
|
'checkLocalPassword',
|
||||||
);
|
);
|
||||||
throw new InvalidCredentialsError();
|
throw new InvalidCredentialsError('Password is not correct');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue