0

I made the Login-Action Tutorial from the symfony site: http://symfony.com/doc/current/cookbook/security/form_login_setup.html

When I do my Login in the form, I get the following error:

The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? 

Here is my security.yml

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        ROLE_USER:        ROLE_USER
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        in_memory:
            memory:
                users:
                    user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                    admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

    access_denied_url: no_access

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

        login:
            pattern:  ^/login
            security: false

        secured_area:
            pattern:    ^/
            anonymous: ~
            form_login:
                login_path: /login
                check_path: /login_check
                default_target_path: home
            logout:
                path:   /logout
                target: /login

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

My Security Controller:

class SecurityController extends Controller
{
    /**
     * @Route("/login", name="login_route")
     * @Template()
     */
    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(
            'TripAdminBundle:Main:login.html.twig',
            array(
                // last username entered by the user
                'last_username' => $lastUsername,
                'error'         => $error,
            )
        );
    }

    /**
     * @Route("/login_check", name="login_check")
     */
    public function loginCheckAction()
    {
        // this controller will not be executed,
        // as the route is handled by the Security system
    }
}

The redirect after Click on the submit Button is to login_check but there is no code in it because symfony says: the route is handled by the Security system Bute I get this error. Can someone help me with this please?

7
  • requires_channel https ? are you on https localhost? login_check must be accessable as well if you have restricted access to ^/ Commented Nov 25, 2015 at 13:02
  • At the moment I#m on localhost, the login area is reachable, only if I submit the button, the redirect is correctly to login_check Route but is not handled by symfony Commented Nov 25, 2015 at 13:07
  • Read at the link you provided about 3. Be Sure /login_check Is Behind a Firewall and the box over this point is important in your case.. In your case pattern pattern: ^/login dont covers login_check so adding $ at the pattern should fix it Commented Nov 25, 2015 at 13:07
  • Sorry, don't know what are you meaning with that. Why is symfony not handling the login_check action? Because when symfony would handle it, it wouldnt say, tht in this action must place a return response. Commented Nov 25, 2015 at 13:11
  • The submission of your form lead a request which uses this login check (auto validation), but you are not yet logged in at first place. So if your firewall except that you have to be at least with ROLE_USER for this route it will fail and the validation will never starts Commented Nov 25, 2015 at 13:17

1 Answer 1

0

return array directly , don't use render method and twig file name . return array( // last username entered by the user 'last_username' => $lastUsername, 'error' => $error, ) );

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.