Symfony Traditional Login无效

时间:2017-08-27 11:07:29

标签: symfony symfony-3.2

无法登录并重定向到主页。我该如何存档?请查看我的剧本。

这是我的登录HTML代码

login.html.twig

{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}

<form action="{{ path('user_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="/account" />
#}

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

这是我的控制器代码

控制器

class SecurityController extends Controller
{
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('UserBundle:Security:login.html.twig', array(
        'last_username' => $lastUsername,
        'error'         => $error,
    ));
 }
}

这是我的安全yml代码

Security.yml

security:
   encoders:
       UserBundle\Entity\User:
           algorithm: bcrypt

  # ...

  providers:
    our_db_provider:
        entity:
            class: UserBundle:User
            # property: username
            # if you're using multiple entity managers
            # manager_name: customer

firewalls:
    main:
        pattern:    ^/admin
        methods: [GET, POST]
        http_basic: ~
        provider: our_db_provider
        form_login:
            # ...
            #default_target_path: after_login_route_name
            #always_use_default_target_path: true       
            #failure_path: login_failure_route_name     
            login_path: login
            check_path: login

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

无法登录并重定向到主页。我该如何存档?请看我的剧本。 实体,存储库,表,用户数据已经存在。

0 个答案:

没有答案