diff --git a/controller/registercontroller.php b/controller/registercontroller.php index 9132681..16c726e 100644 --- a/controller/registercontroller.php +++ b/controller/registercontroller.php @@ -136,9 +136,7 @@ class RegisterController extends Controller { try { $user = $this->registrationService->createAccount($registration, $username, $password); - } catch (RegistrationException $exception) { - return $this->renderError($exception->getMessage(), $exception->getHint()); - } catch (\InvalidArgumentException $exception) { + } catch (\Exception $exception) { // Render form with previously sent values return new TemplateResponse('registration', 'form', [ diff --git a/service/registrationservice.php b/service/registrationservice.php index d14018b..ea8f7cd 100644 --- a/service/registrationservice.php +++ b/service/registrationservice.php @@ -254,7 +254,7 @@ class RegistrationService { * @param string $username * @param string $password * @return \OCP\IUser - * @throws RegistrationException + * @throws RegistrationException|\InvalidTokenException */ public function createAccount(Registration &$registration, $username = null, $password = null) { if($password === null && $registration->getPassword() === null) { @@ -270,6 +270,15 @@ class RegistrationService { $password = $this->crypto->decrypt($registration->getPassword()); } + $this->validateUsername($username); + + /* TODO + * createUser tests username validity once, but validateUsername already checked it, + * but createUser doesn't check if there is a pending registration with that name + * + * And validateUsername will throw RegistrationException while + * createUser throws \InvalidTokenException in NC, \Exception in OC + */ $user = $this->userManager->createUser($username, $password); if ($user === false) { throw new RegistrationException($this->l10n->t('Unable to create user, there are problems with the user backend.'));