From 459c9e0454b1ac1f9408fc8da393a830f68ce427 Mon Sep 17 00:00:00 2001
From: Maxence Lange
Date: Thu, 16 Jan 2020 11:48:06 -0100
Subject: [PATCH 1/2] ignore username input
Signed-off-by: Maxence Lange
---
lib/Controller/RegisterController.php | 13 +++++++++++--
lib/Db/Registration.php | 2 +-
templates/form.php | 2 ++
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/lib/Controller/RegisterController.php b/lib/Controller/RegisterController.php
index dfe82bb..a34c168 100644
--- a/lib/Controller/RegisterController.php
+++ b/lib/Controller/RegisterController.php
@@ -21,6 +21,7 @@ use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\RedirectResponse;
use \OCP\AppFramework\Controller;
use OCP\IURLGenerator;
+use \OCP\IConfig;
use \OCP\IL10N;
class RegisterController extends Controller {
@@ -29,6 +30,8 @@ class RegisterController extends Controller {
private $l10n;
/** @var IURLGenerator */
private $urlgenerator;
+ /** @var IConfig */
+ private $config;
/** @var RegistrationService */
private $registrationService;
/** @var MailService */
@@ -40,12 +43,14 @@ class RegisterController extends Controller {
IRequest $request,
IL10N $l10n,
IURLGenerator $urlgenerator,
+ IConfig $config,
RegistrationService $registrationService,
MailService $mailService
) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->urlgenerator = $urlgenerator;
+ $this->config = $config;
$this->registrationService = $registrationService;
$this->mailService = $mailService;
}
@@ -140,9 +145,13 @@ class RegisterController extends Controller {
* @return RedirectResponse|TemplateResponse
*/
public function createAccount($token) {
- $username = $this->request->getParam('username');
- $password = $this->request->getParam('password');
$registration = $this->registrationService->getRegistrationForToken($token);
+ if ($this->config->getAppValue('registration', 'email_is_login', '0') === '1') {
+ $username = $registration->email;
+ } else {
+ $username = $this->request->getParam('username');
+ }
+ $password = $this->request->getParam('password');
try {
$user = $this->registrationService->createAccount($registration, $username, $password);
diff --git a/lib/Db/Registration.php b/lib/Db/Registration.php
index 46dbbb1..e88b5fa 100644
--- a/lib/Db/Registration.php
+++ b/lib/Db/Registration.php
@@ -47,7 +47,7 @@ use OCP\AppFramework\Db\Entity;
*/
class Registration extends Entity {
public $id;
- protected $email;
+ public $email;
protected $username;
protected $displayname;
protected $password;
diff --git a/templates/form.php b/templates/form.php
index ada251e..51b21eb 100644
--- a/templates/form.php
+++ b/templates/form.php
@@ -23,6 +23,7 @@ script('registration', 'form');
+ getConfig()->getAppValue('registration', 'email_is_login', '0') !== '1' ) { ?>
t('Username')); ?>
+
From 47b01c6639b7f4bce5cba07aaa679aa0286a4ffc Mon Sep 17 00:00:00 2001
From: Joas Schilling
Date: Tue, 18 Aug 2020 17:03:39 +0200
Subject: [PATCH 2/2] Fix minor issues
Signed-off-by: Joas Schilling
---
lib/Controller/RegisterController.php | 8 ++++++--
lib/Db/Registration.php | 2 +-
templates/form.php | 4 ++--
tests/Integration/Controller/RegisterControllerTest.php | 1 +
4 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/lib/Controller/RegisterController.php b/lib/Controller/RegisterController.php
index a34c168..deb7e55 100644
--- a/lib/Controller/RegisterController.php
+++ b/lib/Controller/RegisterController.php
@@ -131,7 +131,11 @@ class RegisterController extends Controller {
);
}
- return new TemplateResponse('registration', 'form', ['email' => $registration->getEmail(), 'token' => $registration->getToken()], 'guest');
+ return new TemplateResponse('registration', 'form', [
+ 'email' => $registration->getEmail(),
+ 'email_is_login' => $this->config->getAppValue('registration', 'email_is_login', '0') === '1',
+ 'token' => $registration->getToken(),
+ ], 'guest');
} catch (RegistrationException $exception) {
return $this->renderError($exception->getMessage(), $exception->getHint());
}
@@ -147,7 +151,7 @@ class RegisterController extends Controller {
public function createAccount($token) {
$registration = $this->registrationService->getRegistrationForToken($token);
if ($this->config->getAppValue('registration', 'email_is_login', '0') === '1') {
- $username = $registration->email;
+ $username = $registration->getEmail();
} else {
$username = $this->request->getParam('username');
}
diff --git a/lib/Db/Registration.php b/lib/Db/Registration.php
index e88b5fa..46dbbb1 100644
--- a/lib/Db/Registration.php
+++ b/lib/Db/Registration.php
@@ -47,7 +47,7 @@ use OCP\AppFramework\Db\Entity;
*/
class Registration extends Entity {
public $id;
- public $email;
+ protected $email;
protected $username;
protected $displayname;
protected $password;
diff --git a/templates/form.php b/templates/form.php
index 51b21eb..c9e81b0 100644
--- a/templates/form.php
+++ b/templates/form.php
@@ -23,7 +23,7 @@ script('registration', 'form');
- getConfig()->getAppValue('registration', 'email_is_login', '0') !== '1' ) { ?>
+
t('Username')); ?>
-
+
diff --git a/tests/Integration/Controller/RegisterControllerTest.php b/tests/Integration/Controller/RegisterControllerTest.php
index 7475f67..b3bb45b 100644
--- a/tests/Integration/Controller/RegisterControllerTest.php
+++ b/tests/Integration/Controller/RegisterControllerTest.php
@@ -108,6 +108,7 @@ class RegisterControllerTest extends TestCase {
$this->request,
$this->l10n,
$this->urlGenerator,
+ $this->config,
$this->registrationService,
$this->mailService
);