douchilian1009 2018-01-06 23:02
浏览 59

Symfony4安全登录表单

I have a problem with login form in Symfony4. I use FOSUserBundle for security on my site, but i can't log in. It's my code:

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

and my controller

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

And when I try to log in, my console send me an error:

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

Passwords and username is ok I think... Why I can't log in?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序