A
A
Anton2016-06-20 17:39:55
symfony
Anton, 2016-06-20 17:39:55

What should I do if the login example from the Symfony3 documentation does not work?

I read the security section, and do everything according to it - everything works with the http_basic form, but with the form - no, and no errors, nothing - it redirects back to an empty form, and writes that I have an anonymous token, I tried to enter both under the user and under admin...
UPD.: I also tried to copy the controller security code from fosuserbundle - the same thing.
UPD.: writes in logs

Symfony\\Component\\Security\\Core\\Exception\\AuthenticationCredentialsNotFoundException(code: 0): A Token was not found in the TokenStorage

//routing.yml
login:
    path:     /login
    defaults: { _controller: AppBundle:Security:login }

logout:
    path: /logout

homepage:
    path: /
    defaults:  { _controller: AppBundle:Default:index }

//security.yml
security:

    encoders:
        Symfony\Component\Security\Core\User\User:
            algorithm: bcrypt
            cost: 12

    providers:
#        db_user_provider:
#            entity:
#                class: "AppBundle:Manager"
        in_memory:
            memory:
                users:
                    ryan:
                        password: $2y$12$1jsx3GlGNP/qKZCFd58KUevrBnVUOLJa6k/2zDI.3YaOVGXvoxhFm
                        roles: 'ROLE_USER'
                    admin:
                        password: $2y$12$GRIwEY47GJ9w4LSqoR4zmuiYTWecWWAM7gKzvblPB3itQ.0rMAH.m
                        roles: 'ROLE_ADMIN'


    firewalls:
        login_firewall:
            pattern:   ^/login$
            anonymous: ~

        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            pattern:    ^/
            #provider: db_user_provider
            #http_basic: ~
            logout:
                path:   /logout
                target: login
            form_login:
                default_target_path: /
                login_path: login
                check_path: login

class SecurityController extends Controller
{
    public function loginAction()
    {
        $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(
            'security/login.html.twig',
            array(
                // last username entered by the user
                'last_username' => $lastUsername,
                'error'         => $error,
            )
        );
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Romanenko, 2016-06-20
@slimus

Have you cleared the cache?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question