Skip to content

Commit

Permalink
Merge pull request #20 from fatguytyson/master
Browse files Browse the repository at this point in the history
Bolt 5.0 compatibility
  • Loading branch information
bobdenotter authored Jan 6, 2022
2 parents 6830c5e + 5f448e3 commit 5f0c150
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Exclude/ProtectedDetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ 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);

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);
Expand Down
20 changes: 14 additions & 6 deletions src/Twig/LoginFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,20 +65,22 @@ public function getLoginForm(bool $withLabels = true, array $labels = []): strin

public function getUsernameField(bool $withLabel, array $labels): string
{
$name = $this->useOldLoginForm() ? 'username' : 'login[username]';
$text = array_key_exists('username', $labels) ? $labels['username'] : 'Username';
$label = $withLabel ? sprintf('<label for="username">%s</label>', $text) : '';
$label = $withLabel ? sprintf('<label for="%s">%s</label>', $name, $text) : '';

$input = '<input type="text" id="username" name="username">';
$input = sprintf('<input type="text" id="username" name="%s">', $name);

return $label . $input;
}

public function getPasswordField(bool $withLabel, array $labels): string
{
$name = $this->useOldLoginForm() ? 'password' : 'login[password]';
$text = array_key_exists('password', $labels) ? $labels['password'] : 'Password';
$label = $withLabel ? sprintf('<label for="password">%s</label>', $text) : '';
$label = $withLabel ? sprintf('<label for="%s">%s</label>', $name, $text) : '';

$input = '<input type="password" id="password" name="password">';
$input = sprintf('<input type="password" id="password" name="%s">', $name);

return $label . $input;
}
Expand All @@ -101,9 +104,10 @@ public function getSubmitButton(array $labels = []): string

public function getCsrfField(): string
{
$token = $this->csrfTokenManager->getToken('authenticate');
$name = $this->useOldLoginForm() ? '_csrf_token' : 'login[_token]';
$token = $this->csrfTokenManager->getToken($this->useOldLoginForm() ? 'authenticate' : 'login_csrf_token');

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

public function getRedirectField(string $group = '', string $pathOrUrl = ''): string
Expand All @@ -118,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 5f0c150

Please sign in to comment.