简体   繁体   English

Symfony登录后未重定向

[英]Symfony not redirecting after login

My code does not give a message when I make a failed attempt to login nor does it redirect when I actually do login. 当我尝试登录失败时,我的代码不会显示消息,也不会在我实际登录时重定向。 Is there any chance someone can help me? 有人可以帮助我吗?

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: ~

This is my controller 这是我的控制器

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,
));
}
}

and this is the twig I am using 这是我正在使用的树枝

{% 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>

这很奇怪,您是否尝试使用路由名称而不是security.yml的default_target_path密钥中的路径?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM