Fix# catch all kinds of exceptions in registercontroller, fixes #134

This commit is contained in:
Pellaeon Lin 2018-04-26 01:36:51 +08:00
parent 15b82cac77
commit ed808ab3e8
2 changed files with 11 additions and 4 deletions

View File

@ -136,9 +136,7 @@ class RegisterController extends Controller {
try { try {
$user = $this->registrationService->createAccount($registration, $username, $password); $user = $this->registrationService->createAccount($registration, $username, $password);
} catch (RegistrationException $exception) { } catch (\Exception $exception) {
return $this->renderError($exception->getMessage(), $exception->getHint());
} catch (\InvalidArgumentException $exception) {
// Render form with previously sent values // Render form with previously sent values
return new TemplateResponse('registration', 'form', return new TemplateResponse('registration', 'form',
[ [

View File

@ -254,7 +254,7 @@ class RegistrationService {
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return \OCP\IUser * @return \OCP\IUser
* @throws RegistrationException * @throws RegistrationException|\InvalidTokenException
*/ */
public function createAccount(Registration &$registration, $username = null, $password = null) { public function createAccount(Registration &$registration, $username = null, $password = null) {
if($password === null && $registration->getPassword() === null) { if($password === null && $registration->getPassword() === null) {
@ -270,6 +270,15 @@ class RegistrationService {
$password = $this->crypto->decrypt($registration->getPassword()); $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); $user = $this->userManager->createUser($username, $password);
if ($user === false) { if ($user === false) {
throw new RegistrationException($this->l10n->t('Unable to create user, there are problems with the user backend.')); throw new RegistrationException($this->l10n->t('Unable to create user, there are problems with the user backend.'));