diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 5bcc01540..e196aee6f 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -20,6 +20,7 @@ import { User } from '../users/user.entity'; import { UsersService } from '../users/users.service'; import { bufferToBase64Url, + checkPassword, hashPassword, } from '../utils/password'; import { TimestampMillis } from '../utils/timestamp'; diff --git a/src/users/user-relation.enum.ts b/src/users/user-relation.enum.ts new file mode 100644 index 000000000..bad202ae5 --- /dev/null +++ b/src/users/user-relation.enum.ts @@ -0,0 +1,10 @@ +/* + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export enum UserRelationEnum { + AUTHTOKENS = 'authTokens', + IDENTITIES = 'identities', +} diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 5371b575d..c0f1a3d88 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -10,6 +10,7 @@ import { Repository } from 'typeorm'; import { AlreadyInDBError, NotInDBError } from '../errors/errors'; import { ConsoleLoggerService } from '../logger/console-logger.service'; import { UserInfoDto } from './user-info.dto'; +import { UserRelationEnum } from './user-relation.enum'; import { User } from './user.entity'; @Injectable() @@ -73,17 +74,16 @@ export class UsersService { * @async * Get the user specified by the username * @param {string} userName the username by which the user is specified - * @param {boolean} [withTokens=false] if the returned user object should contain authTokens + * @param {UserRelationEnum[]} [withRelations=[]] if the returned user object should contain certain relations * @return {User} the specified user */ - async getUserByUsername(userName: string, withTokens = false): Promise { - const relations: string[] = []; - if (withTokens) { - relations.push('authTokens'); - } + async getUserByUsername( + userName: string, + withRelations: UserRelationEnum[] = [], + ): Promise { const user = await this.userRepository.findOne({ where: { userName: userName }, - relations: relations, + relations: withRelations, }); if (user === undefined) { throw new NotInDBError(`User with username '${userName}' not found`);