1
votes

I'm new in symfony and I'm following the login form tutorial(https://symfony.com/doc/2.8/cookbook/security/form_login_setup.html) but I get the following error:

Uncaught PHP Exception LogicException: "The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?" at /var/www/html/app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 157
Context: { "exception": "Object(LogicException)" }

I use the same SecurityController:

class SecurityController extends Controller{


 * @Route("/admin", name="login")

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(
    'security/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
}

security.yml

# To get started with security, check out the documentation:

http://symfony.com/doc/current/book/security.html

security:

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
    app_users:
         ldap:
             service: app.ldap
             base_dn: DC=corp, DC=int
             search_dn: null
             search_password: null
             filter: (uid={username})
             default_roles: ROLE_USER

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~
        # activate different ways to authenticate

        # http_basic: ~
        # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

        # form_login: ~
        # http://symfony.com/doc/current/cookbook/security/form_login_setup.html
    secure:
        provider: app_users
        form_login_ldap:
            service: app.ldap
            dn_string: "uid={username},ou=Users,dc=corp,dc=int"
            check_path: login_check
            login_path: admin
        logout: true
1
What does your security config look like? (app/config/security.yml)Wouter J

1 Answers

0
votes

In your security.yml, try to replace

check_path: login_check

by

check_path: /login_check

And make your method like this :

/**
 * @Route("/login_check", name="login_check")
 */
public function loginCheckAction()
{
    throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}