Skip to content

Commit

Permalink
more precise error handling on user registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Häublein committed Jun 13, 2021
1 parent a805c47 commit 5aaeaaf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Symfony-API/src/Api/UserApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ public function logoutUser(&$responseCode, array &$responseHeaders)
public function registerUser(RegistrationInformation $registration, &$responseCode, array &$responseHeaders) {
if (!$this->allowRegistration) {
$this->logger->info('registration is disabled but was accessed');
$responseCode = 403;
return $this->generateApiError("registration is not allowed");
}
if ($this->entityManager->getRepository(User::class)->findOneBy(['username' => $registration->getUsername()])) {
$this->logger->error('user already exists');
$responseCode = 403;
return $this->generateApiError("username can not be used");
}
$user = new User();
$user->setUsername($registration->getUsername());
$user->setEmail($registration->getEmail());
Expand Down

0 comments on commit 5aaeaaf

Please sign in to comment.