From 9f9f5f24093a45fd84d8fac73228fcf541e114a5 Mon Sep 17 00:00:00 2001 From: Tyson Green Date: Mon, 6 Sep 2021 15:07:22 -0700 Subject: [PATCH 1/3] Bolt 5.0 compatability --- src/Exclude/ProtectedDetailController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Exclude/ProtectedDetailController.php b/src/Exclude/ProtectedDetailController.php index 45d338d..d5be44a 100644 --- a/src/Exclude/ProtectedDetailController.php +++ b/src/Exclude/ProtectedDetailController.php @@ -42,7 +42,7 @@ public function __construct(DetailController $detailController, Config $config) * * @param string|int $slugOrId */ - public function record($slugOrId, ?string $contentTypeSlug = null, bool $requirePublished = true): Response + public function record($slugOrId, ?string $contentTypeSlug = null, bool $requirePublished = true, string $_locale = null): Response { $contentType = ContentType::factory($contentTypeSlug, $this->config->get('contenttypes')); $this->applyAllowForGroupsGuard($contentType); @@ -50,7 +50,7 @@ public function record($slugOrId, ?string $contentTypeSlug = null, bool $require return $this->detailController->record($slugOrId, $contentTypeSlug, $requirePublished); } - public function contentByFieldValue(string $contentTypeSlug, string $field, string $value): Response + public function contentByFieldValue(string $contentTypeSlug, string $field, string $value, string $_locale = null): Response { $contentType = ContentType::factory($contentTypeSlug, $this->config->get('contenttypes')); $this->applyAllowForGroupsGuard($contentType); From f22451f2f962f1dc7dbdb0d0c91e2bae31d80a07 Mon Sep 17 00:00:00 2001 From: Tyson Green Date: Mon, 6 Sep 2021 16:33:32 -0700 Subject: [PATCH 2/3] Bolt 5.0 compatibility --- src/Twig/LoginFormExtension.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Twig/LoginFormExtension.php b/src/Twig/LoginFormExtension.php index 302dbba..4f1811b 100644 --- a/src/Twig/LoginFormExtension.php +++ b/src/Twig/LoginFormExtension.php @@ -7,6 +7,7 @@ use Bolt\UsersExtension\ExtensionConfigInterface; use Bolt\UsersExtension\ExtensionConfigTrait; use Bolt\UsersExtension\Utils\ExtensionUtils; +use Bolt\Version; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Twig\Extension\AbstractExtension; @@ -64,20 +65,22 @@ public function getLoginForm(bool $withLabels = true, array $labels = []): strin public function getUsernameField(bool $withLabel, array $labels): string { + $name = Version::compare('4', '=') ? 'username' : 'login[username]'; $text = array_key_exists('username', $labels) ? $labels['username'] : 'Username'; - $label = $withLabel ? sprintf('', $text) : ''; + $label = $withLabel ? sprintf('', $name, $text) : ''; - $input = ''; + $input = sprintf('', $name); return $label . $input; } public function getPasswordField(bool $withLabel, array $labels): string { + $name = Version::compare('4', '=') ? 'password' : 'login[password]'; $text = array_key_exists('password', $labels) ? $labels['password'] : 'Password'; - $label = $withLabel ? sprintf('', $text) : ''; + $label = $withLabel ? sprintf('', $name, $text) : ''; - $input = ''; + $input = sprintf('', $name); return $label . $input; } @@ -101,9 +104,10 @@ public function getSubmitButton(array $labels = []): string public function getCsrfField(): string { - $token = $this->csrfTokenManager->getToken('authenticate'); + $name = Version::compare('4.2.3', '>=') ? '_csrf_token' : 'login[_token]'; + $token = $this->csrfTokenManager->getToken('login_csrf_token'); - return sprintf('', $token); + return sprintf('', $name, $token); } public function getRedirectField(string $group = '', string $pathOrUrl = ''): string From 5f448e3a238c283783f2bd4ca17d5ab2890ee179 Mon Sep 17 00:00:00 2001 From: Tyson Green Date: Mon, 6 Sep 2021 16:50:03 -0700 Subject: [PATCH 3/3] 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', '>='); + } }