Skip to content

Commit

Permalink
Regression: Fixed broken 2FA form [#2109]
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Apr 7, 2021
1 parent c4d90bf commit 9fca08a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#bugfix)
* Fixed missing `admin-preset.css` in multisite environments
* Regression: Fixed broken 2FA form [#2109](https://github.com/getgrav/grav-plugin-admin/issues/2109)

# v1.10.9
## 04/06/2021
Expand Down
9 changes: 4 additions & 5 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Grav\Plugin\Admin\AdminController;
use Grav\Plugin\Admin\Twig\AdminTwigExtension;
use Grav\Plugin\Admin\WhiteLabel;
use Grav\Plugin\FlexObjects\FlexFormFactory;
use Grav\Plugin\Form\Form;
use Grav\Plugin\Form\Forms;
use Grav\Plugin\Login\Login;
Expand Down Expand Up @@ -684,10 +683,10 @@ public function onTwigSiteVariables()
$twig->twig_vars['forms'] = $forms;

// preserve form validation
if (!isset($twig->twig_vars['form'])) {
if ($this->admin->form) {
$twig->twig_vars['form'] = $this->admin->form;
} elseif (isset($header->form)) {
if ($this->admin->form) {
$twig->twig_vars['form'] = $this->admin->form;
} elseif (!isset($twig->twig_vars['form'])) {
if (isset($header->form)) {
$twig->twig_vars['form'] = new Form($page);
} elseif (isset($header->forms)) {
$twig->twig_vars['form'] = new Form($page, null, reset($header->forms));
Expand Down
11 changes: 8 additions & 3 deletions classes/plugin/Controllers/Login/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,26 @@ public function taskTwofa(): ResponseInterface
return $this->createRedirectResponse('/');
}

$login = $this->getLogin();

$this->page = $this->createPage('login');
$this->form = $this->getForm('admin-login-twofa');
$this->form = $this->getForm('login-twofa');
try {
$this->checkNonce();
} catch (PageExpiredException $e) {
$this->setMessage($this->translate('PLUGIN_ADMIN.INVALID_SECURITY_TOKEN'), 'error');

return $this->createDisplayResponse();
// Failed 2FA nonce check, logout and redirect.
$login->logout(['admin' => true]);
$this->form->reset();

return $this->createRedirectResponse('/');
}


$post = $this->getPost();
$data = $post['data'] ?? [];

$login = $this->getLogin();
try {
$twoFa = $login->twoFactorAuth();
} catch (TwoFactorAuthException $e) {
Expand Down
2 changes: 0 additions & 2 deletions themes/grav/templates/partials/login-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
{% endblock %}

{% block form %}
{% set form = forms['login'] %}

{% for field_name,field in form.fields %}
{% if field.type %}
{% set field = field|merge({ name: field.name ?? field_name }) %}
Expand Down
2 changes: 0 additions & 2 deletions themes/grav/templates/partials/login-twofa.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

{% block form %}

{% set form = forms['login-twofa'] %}

{% for field_name, field in form.fields %}
{% if field.type %}
{% set field = field|merge({ name: field.name ?? field_name }) %}
Expand Down

0 comments on commit 9fca08a

Please sign in to comment.