mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
feat(auth): password change requires old password
By checking the "old" password of the user prior to a password change, the password change function is more secured against abuse. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
20b0ded223
commit
277e2fb1ca
4 changed files with 37 additions and 2 deletions
|
@ -9,10 +9,10 @@ import {
|
|||
ConflictException,
|
||||
Controller,
|
||||
Delete,
|
||||
NotFoundException,
|
||||
Post,
|
||||
Put,
|
||||
Req,
|
||||
UnauthorizedException,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { Session } from 'express-session';
|
||||
|
@ -70,6 +70,10 @@ export class AuthController {
|
|||
@Body() changePasswordDto: UpdatePasswordDto,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await this.identityService.loginWithLocalIdentity(
|
||||
user,
|
||||
changePasswordDto.currentPassword,
|
||||
);
|
||||
await this.identityService.updateLocalPassword(
|
||||
user,
|
||||
changePasswordDto.newPassword,
|
||||
|
@ -77,7 +81,9 @@ export class AuthController {
|
|||
return;
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
throw new UnauthorizedException(
|
||||
'Verifying your identity with the current password did not work.',
|
||||
);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue