Skip to content

Commit

Permalink
Bolt 5.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fatguytyson committed Sep 6, 2021
1 parent f22451f commit 5f448e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Twig/LoginFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<label for="%s">%s</label>', $name, $text) : '';

Expand All @@ -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('<label for="%s">%s</label>', $name, $text) : '';

Expand Down Expand Up @@ -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('<input type="hidden" name="%s" value="%s">', $name, $token);
}
Expand All @@ -122,4 +122,8 @@ public function getRedirectField(string $group = '', string $pathOrUrl = ''): st

return sprintf('<input type="hidden" name="_target_path" value="%s">', $pathOrUrl);
}

private function useOldLoginForm(): bool{
return Version::compare('4.2.2', '>=');
}
}

0 comments on commit 5f448e3

Please sign in to comment.