Twig 角色检查是重定向
Twig roles checking is redirect
当我尝试使用 is_granted()
而不是 return 布尔值检查 Twig 中的用户角色时,只需重定向到登录路径。
{% if is_granted('ROLE_SUPER_ADMIN') == true %} # without == true tested.
<a href="{{ path('foo_bar') }}">Foo Bar Link</a>
{% endif %}
Symfony:4.1
我更改验证器后问题解决了
更改前:
$isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
if ($isPasswordValid) {
return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
}
并将其更改为:
$isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
if ($isPasswordValid or $token->getUser() instanceof User) {
return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
}
我将 $token->getUser() instanceof User
添加到条件中。
当我尝试使用 is_granted()
而不是 return 布尔值检查 Twig 中的用户角色时,只需重定向到登录路径。
{% if is_granted('ROLE_SUPER_ADMIN') == true %} # without == true tested.
<a href="{{ path('foo_bar') }}">Foo Bar Link</a>
{% endif %}
Symfony:4.1
我更改验证器后问题解决了
更改前:
$isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
if ($isPasswordValid) {
return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
}
并将其更改为:
$isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
if ($isPasswordValid or $token->getUser() instanceof User) {
return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
}
我将 $token->getUser() instanceof User
添加到条件中。