diff --git a/back/src/users/dto/user.dto.ts b/back/src/users/dto/user.dto.ts index 9d56847..b450afb 100644 --- a/back/src/users/dto/user.dto.ts +++ b/back/src/users/dto/user.dto.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty, IsPositive, IsOptional, IsEmail, NotContains, MaxLength } from 'class-validator' +import { IsNotEmpty, IsPositive, IsOptional, IsEmail, NotContains, MaxLength, IsAlphanumeric } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' import { Express } from 'express' @@ -10,6 +10,7 @@ export class UserDto { @IsNotEmpty() @NotContains(' ') + @IsAlphanumeric() @MaxLength(15) readonly username: string diff --git a/back/src/users/entity/user.entity.ts b/back/src/users/entity/user.entity.ts index ca9eef6..f2148bd 100644 --- a/back/src/users/entity/user.entity.ts +++ b/back/src/users/entity/user.entity.ts @@ -19,7 +19,7 @@ export class User { @Column({ unique: true }) ftId: number - @Column({ unique: true, nullable: true }) + @Column({ nullable: true }) email: string @Column({ select: false, nullable: true }) diff --git a/back/src/users/users.controller.ts b/back/src/users/users.controller.ts index 22ef818..87ec09b 100644 --- a/back/src/users/users.controller.ts +++ b/back/src/users/users.controller.ts @@ -211,6 +211,11 @@ export class UsersController { ): Promise { const user = await this.usersService.findUser(+profile.id) if (user == null) throw new BadRequestException('User not found.') + if (payload.username !== undefined) { + const user2: User | null = await this.usersService.findUserByName(payload.username).catch(() => null) + const user2ftId = user2?.ftId + if (user2 !== null && user2ftId !== +profile.id) throw new BadRequestException('Username already taken.') + } await this.usersService.update(user, payload) return user }