当我尝试登录失败时,我的代码不会给出消息,也不会在我实际登录时重定向。有人有可能帮助我吗?
security.yml
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/security.html
security:
providers:
in_memory:
memory:
users:
inkoper:
password: TeslaModelS
roles: 'ROLE_INKOPER'
admin:
password: GoudenEikel
roles: 'ROLE_ADMIN'
verkoper:
password: Barracuda
roles: 'ROLE_INKOPER'
magazijnmeester:
password: kitten
roles: 'ROLE_MAGAZIJNMEESTER'
encoders:
Symfony\Component\Security\Core\User\User: plaintext
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/artikel/alle, roles: [ROLE_INKOPER, ROLE_ADMIN] }
- { path: ^/artikel/wijzig/*, roles: [ROLE_INKOPER, ROLE_MAGAZIJNMEESTER] }
- { path: ^/artikel/verwijder/* , roles: ROLE_INKOPER }
- { path: ^/artikel/magazijnlocatie/* , roles: ROLE_MAGAZIJNMEESTER }
- { path: ^/artikel/* , roles: ROLE_INKOPER }
- { path: ^/* , roles: ROLE_ADMIN }
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
form_login:
login_path: /login
check_path: /login_check
always_use_default_target_path: true
default_target_path: /artikel/alle
anonymous: ~
# activate different ways to authenticate
# http://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
http_basic: ~
# http://symfony.com/doc/current/cookbook/security/form_login_setup.html
#form_login: ~
这是我的控制器
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class SecurityController extends Controller
{
/**
* @Route("/login", name="login")
*/
public function loginAction(Request $request){
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
}
}
这是我正在使用的树枝
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<form action="{{ path('login') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
{#
If you want to control the URL the user
is redirected to on success (more details below)
<input type="hidden" name="_target_path" value="/artikel/alle" />
#}
<button type="submit">login</button>
</form>
答案 0 :(得分:0)
这很奇怪,您是否尝试使用路由名而不是security.yml的default_target_path键中的路径?