Merge branch 'enh/noid/using-email-as-login' into master

* enh/noid/using-email-as-login:
  Fix minor issues
  ignore username input
This commit is contained in:
Joas Schilling 2020-08-18 17:06:02 +02:00
commit 1fe3f0b29a
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
3 changed files with 19 additions and 3 deletions

View File

@ -21,6 +21,7 @@ use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\RedirectResponse; use \OCP\AppFramework\Http\RedirectResponse;
use \OCP\AppFramework\Controller; use \OCP\AppFramework\Controller;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use \OCP\IConfig;
use \OCP\IL10N; use \OCP\IL10N;
class RegisterController extends Controller { class RegisterController extends Controller {
@ -29,6 +30,8 @@ class RegisterController extends Controller {
private $l10n; private $l10n;
/** @var IURLGenerator */ /** @var IURLGenerator */
private $urlgenerator; private $urlgenerator;
/** @var IConfig */
private $config;
/** @var RegistrationService */ /** @var RegistrationService */
private $registrationService; private $registrationService;
/** @var MailService */ /** @var MailService */
@ -40,12 +43,14 @@ class RegisterController extends Controller {
IRequest $request, IRequest $request,
IL10N $l10n, IL10N $l10n,
IURLGenerator $urlgenerator, IURLGenerator $urlgenerator,
IConfig $config,
RegistrationService $registrationService, RegistrationService $registrationService,
MailService $mailService MailService $mailService
) { ) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->l10n = $l10n; $this->l10n = $l10n;
$this->urlgenerator = $urlgenerator; $this->urlgenerator = $urlgenerator;
$this->config = $config;
$this->registrationService = $registrationService; $this->registrationService = $registrationService;
$this->mailService = $mailService; $this->mailService = $mailService;
} }
@ -126,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) { } catch (RegistrationException $exception) {
return $this->renderError($exception->getMessage(), $exception->getHint()); return $this->renderError($exception->getMessage(), $exception->getHint());
} }
@ -140,9 +149,13 @@ class RegisterController extends Controller {
* @return RedirectResponse|TemplateResponse * @return RedirectResponse|TemplateResponse
*/ */
public function createAccount($token) { public function createAccount($token) {
$username = $this->request->getParam('username');
$password = $this->request->getParam('password');
$registration = $this->registrationService->getRegistrationForToken($token); $registration = $this->registrationService->getRegistrationForToken($token);
if ($this->config->getAppValue('registration', 'email_is_login', '0') === '1') {
$username = $registration->getEmail();
} else {
$username = $this->request->getParam('username');
}
$password = $this->request->getParam('password');
try { try {
$user = $this->registrationService->createAccount($registration, $username, $password); $user = $this->registrationService->createAccount($registration, $username, $password);

View File

@ -23,6 +23,7 @@ script('registration', 'form');
<img id="email-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/mail.svg')); ?>" alt=""/> <img id="email-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/mail.svg')); ?>" alt=""/>
</p> </p>
<?php if ($_['email_is_login']) { ?>
<p class="groupmiddle"> <p class="groupmiddle">
<input type="text" name="username" id="username" value="<?php if (!empty($_['entered_data']['user'])) { <input type="text" name="username" id="username" value="<?php if (!empty($_['entered_data']['user'])) {
p($_['entered_data']['user']); p($_['entered_data']['user']);
@ -30,6 +31,7 @@ script('registration', 'form');
<label for="username" class="infield"><?php p($l->t('Username')); ?></label> <label for="username" class="infield"><?php p($l->t('Username')); ?></label>
<img id="username-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/user.svg')); ?>" alt=""/> <img id="username-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/user.svg')); ?>" alt=""/>
</p> </p>
<?php } ?>
<p class="groupbottom"> <p class="groupbottom">
<input type="password" name="password" id="password" placeholder="<?php p($l->t('Password')); ?>"/> <input type="password" name="password" id="password" placeholder="<?php p($l->t('Password')); ?>"/>

View File

@ -108,6 +108,7 @@ class RegisterControllerTest extends TestCase {
$this->request, $this->request,
$this->l10n, $this->l10n,
$this->urlGenerator, $this->urlGenerator,
$this->config,
$this->registrationService, $this->registrationService,
$this->mailService $this->mailService
); );