From 5f448e3a238c283783f2bd4ca17d5ab2890ee179 Mon Sep 17 00:00:00 2001 From: Tyson Green Date: Mon, 6 Sep 2021 16:50:03 -0700 Subject: [PATCH] Bolt 5.0 compatibility --- src/Twig/LoginFormExtension.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Twig/LoginFormExtension.php b/src/Twig/LoginFormExtension.php index 4f1811b..a8dd244 100644 --- a/src/Twig/LoginFormExtension.php +++ b/src/Twig/LoginFormExtension.php @@ -65,7 +65,7 @@ public function getLoginForm(bool $withLabels = true, array $labels = []): strin public function getUsernameField(bool $withLabel, array $labels): string { - $name = Version::compare('4', '=') ? 'username' : 'login[username]'; + $name = $this->useOldLoginForm() ? 'username' : 'login[username]'; $text = array_key_exists('username', $labels) ? $labels['username'] : 'Username'; $label = $withLabel ? sprintf('', $name, $text) : ''; @@ -76,7 +76,7 @@ public function getUsernameField(bool $withLabel, array $labels): string public function getPasswordField(bool $withLabel, array $labels): string { - $name = Version::compare('4', '=') ? 'password' : 'login[password]'; + $name = $this->useOldLoginForm() ? 'password' : 'login[password]'; $text = array_key_exists('password', $labels) ? $labels['password'] : 'Password'; $label = $withLabel ? sprintf('', $name, $text) : ''; @@ -104,8 +104,8 @@ public function getSubmitButton(array $labels = []): string public function getCsrfField(): string { - $name = Version::compare('4.2.3', '>=') ? '_csrf_token' : 'login[_token]'; - $token = $this->csrfTokenManager->getToken('login_csrf_token'); + $name = $this->useOldLoginForm() ? '_csrf_token' : 'login[_token]'; + $token = $this->csrfTokenManager->getToken($this->useOldLoginForm() ? 'authenticate' : 'login_csrf_token'); return sprintf('', $name, $token); } @@ -122,4 +122,8 @@ public function getRedirectField(string $group = '', string $pathOrUrl = ''): st return sprintf('', $pathOrUrl); } + + private function useOldLoginForm(): bool{ + return Version::compare('4.2.2', '>='); + } }