token === null || $request->token === '') { throw new BadRequestException('token is required'); } if ($request->password === null || $request->password === '') { throw new BadRequestException('password is required'); } if (strlen($request->password) < 8) { throw new BadRequestException( 'password must be at least 8 characters', ); } $token = $this->tokenRepository->findByToken($request->token); if ($token === null) { throw new DomainException('token not found'); } if ($token->getAvailableTo() < $this->clock->now()) { throw new DomainException('token expired'); } $user = $token->getUser(); if ($user->getPasswordHash() !== null) { throw new DomainException('account already confirmed'); } $user->setPasswordHash( $this->passwordHasher->hash($request->password), ); $confirmedUser = $this->userRepository->update($user); $this->tokenRepository->delete($token->getId()); return $confirmedUser; } }