Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/controllers/user-management/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
BadRequestException,
Body,
Controller,
ForbiddenException,
Get,
InternalServerErrorException,
Logger,
NotFoundException,
Param,
ParseIntPipe,
Expand All @@ -12,10 +14,7 @@ import {
Query,
Req,
UseGuards,
ForbiddenException,
UnauthorizedException,
} from "@nestjs/common";
import { Logger } from "@nestjs/common";
import {
ApiBearerAuth,
ApiForbiddenResponse,
Expand All @@ -34,8 +33,8 @@ import { UpdateUserDto } from "@dto/user-management/update-user.dto";
import { UserResponseDto } from "@dto/user-response.dto";
import { ErrorCodes } from "@entities/enum/error-codes.enum";
import {
checkIfUserIsGlobalAdmin,
checkIfUserHasAccessToOrganization,
checkIfUserIsGlobalAdmin,
OrganizationAccessScope,
} from "@helpers/security-helper";
import { UserService } from "@services/user-management/user.service";
Expand Down Expand Up @@ -171,6 +170,12 @@ export class UserController {
return user;
} catch (err) {
AuditLog.fail(ActionType.UPDATE, User.name, req.user.userId, id);
if (
err instanceof QueryFailedError &&
err.message.startsWith("duplicate key value violates unique constraint")
) {
throw new BadRequestException(ErrorCodes.EmailAlreadyInUse);
}
throw err;
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/services/user-management/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
BadRequestException,
forwardRef,
Inject,
Injectable,
Logger,
forwardRef,
} from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import * as bcrypt from "bcryptjs";
Expand All @@ -22,9 +22,7 @@ import { Profile } from "passport-saml";
import { ListAllUsersMinimalResponseDto } from "@dto/list-all-users-minimal-response.dto";
import { ListAllEntitiesDto } from "@dto/list-all-entities.dto";
import { CreateNewKombitUserDto } from "@dto/user-management/create-new-kombit-user.dto";
import * as nodemailer from "nodemailer";
import { Organization } from "@entities/organization.entity";
import SMTPTransport from "nodemailer/lib/smtp-transport";
import { PermissionType } from "@enum/permission-type.enum";
import { ConfigService } from "@nestjs/config";
import { isPermissionType } from "@helpers/security-helper";
Expand Down Expand Up @@ -200,11 +198,8 @@ export class UserService {
private async setPasswordHash(mappedUser: User, password: string) {
this.checkPassword(password);
// Hash password with bcrpyt
// this.logger.verbose("Generating salt");
const salt = await bcrypt.genSalt(10);
// this.logger.verbose("Generating hash");
mappedUser.passwordHash = await bcrypt.hash(password, salt);
// this.logger.verbose(`Generated hash: '${mappedUser.passwordHash}'`);
}

private checkPassword(password: string) {
Expand Down