Symfony 3.1登录表单上的凭据无效错误

时间:2018-03-05 10:02:07

标签: php symfony login symfony-3.1

我在Symfony 3.1中实现了标准登录fom,登录后我收到消息:“凭证无效”。 这是标准的Symfony登录表单实现。

security.yml:

security:

# http://symfony.com/doc/current/book/security.html#where-do-users-
come-from-user-providers
providers:
    in_memory:
        memory: ~
    our_db_provider:
        entity:
            class: AppBundle:User
            property: username

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~
        # activate different ways to authenticate

        # http_basic: ~
        # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

        # form_login: ~
        # http://symfony.com/doc/current/cookbook/security/form_login_setup.html
        pattern:    ^/
        #http_basic: ~
        provider: our_db_provider

        form_login:
            login_path: login
            check_path: login
            target_path_parameter: about

encoders:
    AppBundle\Entity\User:
        algorithm: bcrypt

access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

的LoginController: 在登录控制器类下面使用loginAction并清空loginCheckAction

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class LoginController extends Controller
{
    /**
     * @Route("/login", name="login")
     */
    public function loginAction(Request $request)
    {
        $authenticationUtils = $this->get('security.authentication_utils');
        $error = $authenticationUtils->getLastAuthenticationError();
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render('user/login.html.twig', array(
            'last_username' => $lastUsername,
            'error'         => $error,
        ));
    }

    /**
     * @Route("/login_check", name="login_check")
     */
    public function loginCheckAction()
    {

    }
}

在我的twig文件下面,path(login), 的 login.html.twig:

<div id="wrapper">
        <div id="container">
            <div id="status">
                <p>
                    {% 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" />

                    <input type="hidden" name="_target_path" value="about" />

                    <button type="submit">login</button>
                </form>
                </p>
            </div>
        </div>
    </div>

如果我将树枝中的path(login)更改为path(login_check)情况相同......仍然是“无效的凭据”....

0 个答案:

没有答案