mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
Rename local password check method
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
277e2fb1ca
commit
820a1ae43a
4 changed files with 8 additions and 8 deletions
|
@ -70,7 +70,7 @@ export class AuthController {
|
||||||
@Body() changePasswordDto: UpdatePasswordDto,
|
@Body() changePasswordDto: UpdatePasswordDto,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this.identityService.loginWithLocalIdentity(
|
await this.identityService.checkLocalPassword(
|
||||||
user,
|
user,
|
||||||
changePasswordDto.currentPassword,
|
changePasswordDto.currentPassword,
|
||||||
);
|
);
|
||||||
|
|
|
@ -102,9 +102,9 @@ describe('IdentityService', () => {
|
||||||
) as Identity;
|
) as Identity;
|
||||||
identity.passwordHash = await hashPassword(password);
|
identity.passwordHash = await hashPassword(password);
|
||||||
user.identities = Promise.resolve([identity]);
|
user.identities = Promise.resolve([identity]);
|
||||||
await expect(
|
await expect(service.checkLocalPassword(user, password)).resolves.toEqual(
|
||||||
service.loginWithLocalIdentity(user, password),
|
undefined,
|
||||||
).resolves.toEqual(undefined);
|
);
|
||||||
});
|
});
|
||||||
describe('fails', () => {
|
describe('fails', () => {
|
||||||
it('when user has no local identity', async () => {
|
it('when user has no local identity', async () => {
|
||||||
|
|
|
@ -73,20 +73,20 @@ export class IdentityService {
|
||||||
* @param {string} password - the password to use
|
* @param {string} password - the password to use
|
||||||
* @throws {NotInDBError} the specified user can't be logged in
|
* @throws {NotInDBError} the specified user can't be logged in
|
||||||
*/
|
*/
|
||||||
async loginWithLocalIdentity(user: User, password: string): Promise<void> {
|
async checkLocalPassword(user: User, password: string): Promise<void> {
|
||||||
const internalIdentity: Identity | undefined =
|
const internalIdentity: Identity | undefined =
|
||||||
await getFirstIdentityFromUser(user, ProviderType.LOCAL);
|
await getFirstIdentityFromUser(user, ProviderType.LOCAL);
|
||||||
if (internalIdentity === undefined) {
|
if (internalIdentity === undefined) {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`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.`,
|
||||||
'loginWithLocalIdentity',
|
'checkLocalPassword',
|
||||||
);
|
);
|
||||||
throw new NotInDBError();
|
throw new NotInDBError();
|
||||||
}
|
}
|
||||||
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.`,
|
||||||
'loginWithLocalIdentity',
|
'checkLocalPassword',
|
||||||
);
|
);
|
||||||
throw new NotInDBError();
|
throw new NotInDBError();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ export class LocalStrategy extends PassportStrategy(Strategy, 'local') {
|
||||||
const user = await this.userService.getUserByUsername(username, [
|
const user = await this.userService.getUserByUsername(username, [
|
||||||
UserRelationEnum.IDENTITIES,
|
UserRelationEnum.IDENTITIES,
|
||||||
]);
|
]);
|
||||||
await this.identityService.loginWithLocalIdentity(user, password);
|
await this.identityService.checkLocalPassword(user, password);
|
||||||
return user;
|
return user;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
|
Loading…
Reference in a new issue