Symfony Traditional Login not working

130 views Asked by At

Can not login and redirect to home page. How can i archive this? please look in my script.

here is my login html code

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>

here is my controller code

Controller

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

here is my Security yml code

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 }

Can not login and redirect to home page. How can i archive this? please look in my script. entity, repository, table, user data already exists.

0

There are 0 answers