Symfony4安全登录表单

时间:2018-01-06 23:02:04

标签: php symfony security fosuserbundle

我在Symfony4中遇到登录表单问题。我在我的网站上使用FOSUserBundle来保证安全,但我无法登录。这是我的代码:

security.yaml

security:
# https://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
encoders:
    App\Entity\User:
        algorithm: sha512
providers:
    user_provider:
        entity:
            class: App\Entity\User

firewalls:

    main:
        anonymous: ~
        provider: user_provider
        form_login:
            login_path: security_login
            check_path: security_login

login.html.twig

{% extends 'base.html.twig' %}
{% block body %}
{% if error %}
    <div class="error">{{ error.messageKey|trans(error.messageData, 
'security') }}</div>
{% endif %}
{{ form_start(form) }}
    {{ form_row(form._username) }}
    {{ form_row(form._password) }}
    <button type="submit">Zaloguj</button>
{{ form_end(form) }}
{% endblock %}

和我的控制器

public function login(Request $r, AuthenticationUtils $authUtils) {
    $error = $authUtils->getLastAuthenticationError();

    $lastUsername = $authUtils->getLastUsername();

    $form = $this->createForm(LoginType::class, [
        '_username' => $lastUsername
    ]);

    return $this->render('home/login.html.twig', array(
        'form' => $form->createView(),
        'error' => $error
    ));
}

当我尝试登录时,我的控制台发给我一个错误:

[info] Authentication request failed
[debug] Authentication failure, redirect triggered

密码和用户名是好的我想...为什么我无法登录?

0 个答案:

没有答案