diff --git a/backend/app/User/UseCases/SignupUser/SignupUser.php b/backend/app/User/UseCases/SignupUser/SignupUser.php index 7f2c78e..7228e87 100644 --- a/backend/app/User/UseCases/SignupUser/SignupUser.php +++ b/backend/app/User/UseCases/SignupUser/SignupUser.php @@ -15,6 +15,8 @@ class SignupUser { private const MIN_PASSWORD_LENGTH = 8; + private const DISPLAY_NAME_PATTERN = '/^[a-z0-9_-]{3,30}$/'; + public function __construct( private UserRepository $userRepo, private PasswordHasher $hasher, @@ -29,6 +31,19 @@ class SignupUser if ($request->email === null || $request->email === '') { throw new BadRequestException('email is required'); } + if ($request->displayName === null || $request->displayName === '') { + throw new BadRequestException('displayName is required'); + } + if ( + preg_match( + self::DISPLAY_NAME_PATTERN, + $request->displayName, + ) !== 1 + ) { + throw new BadRequestException( + 'displayName must be 3-30 chars of [a-z0-9_-]' + ); + } if ($request->password === null || $request->password === '') { throw new BadRequestException('password is required'); } @@ -47,11 +62,16 @@ class SignupUser if ($this->userRepo->findByEmail($email) !== null) { throw new DomainException('email already registered'); } + if ($this->userRepo->findByDisplayName($request->displayName) !== null) { + throw new DomainException('displayName already taken'); + } return $this->userRepo->create(new CreateUserDto( email: $email, + displayName: $request->displayName, passwordHash: $this->hasher->hash($request->password), isAdmin: false, + emailConfirmedAt: null, )); } } diff --git a/backend/app/User/UseCases/SignupUser/SignupUserRequest.php b/backend/app/User/UseCases/SignupUser/SignupUserRequest.php index b6f809f..e202131 100644 --- a/backend/app/User/UseCases/SignupUser/SignupUserRequest.php +++ b/backend/app/User/UseCases/SignupUser/SignupUserRequest.php @@ -6,6 +6,7 @@ class SignupUserRequest { public function __construct( public ?string $email, + public ?string $displayName, public ?string $password, ) {} }