Question

I can't access to my login page and I don't know why...

security.xml :

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

        login:
            pattern:  ^/admin/login$
            security: false

        secured_area:
            pattern:    ^/admin
            remember_me:
                key:      "%secret%"
                lifetime: 604800 # 7 jours en secondes
                path:     /login
                domain:   ~ # Prend la valeur par défaut du domaine courant depuis $_SERVER
            form_login:
                check_path: _login_check
                login_path: _admin_login
                default_target_path: /admin
                always_use_default_target_path: true
            logout:
                path:   _admin_logout
                target: /
            #anonymous: ~
            #http_basic:
            #    realm: "Secured Demo Area"

    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
        - { path: ^/admin, roles: [ROLE_ADMIN] }
        - { path: ^/, roles: [ROLE_USER, ROLE_ADMIN] }

routing.yml :

_admin_login:
    resource: "@TestBackBundle/Controller/SecureController.php"
    type:     annotation

secureController.php :

...

    /**
     * @Route("/admin")
     */
    class SecureController extends Controller
    {
        /**
         * @Route("/login", name="_admin_login")
         * @Template()
         */
        public function loginAction(Request $request)
        {
            if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
                $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
            } else {
                $error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
            }

            return array(
                'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
                'error'         => $error,
            );
        }

        /**
         * @Route("/login_check", name="_login_check")
         */
        public function securityCheckAction()
        {
            // The security layer will intercept this request
        }

        /**
         * @Route("/logout", name="_admin_logout")
         */
        public function logoutAction()
        {
            // The security layer will intercept this request
        }
    }

When I test to access to

http://site1.local/app_dev.php/admin

I have this error : No route found for "GET /admin"

Why routing on my login page doesn't work ?

Was it helpful?

Solution

I guess its this route: http://site1.local/app_dev.php/admin/login

You have to make it called "indexAction", when you just wanna call it by http://site1.local/app_dev.php/admin

Explanation:

All routes who access this class go over /admin

If you wanna show content at /admin you have to create "indexAction"

Then all other actions, for example loginAction has /login as route

So you access the class "/admin" and access the loginAction "/login" so its /admin/login/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top