Symfony2, unable to log in, maybe the reason is the translation?

I cannot understand why I cannot log in.

I get the error message β€œThe controller should return a response (zero value). Have you forgotten to add a return statement to your controller?”

(and print a message from SecurityController, if I uncommented, loginCheckAction (route sec_login_check), which, as I understand it, should never be printed (= completed).

I deleted the translation, removed any prefixes (for example, security) from the entry route and created a new project. However, I still get this error.

// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\demo\src\Demo\DemoBundle\Controller\SecurityController.php

<?php

namespace Demo\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;


use Demo\DemoBundle\Entity\User;

/** 
 * Class SecurityController
 * 
 * @Route("/security")
 * @package Demo\DemoBundle\\Controller
 */
class SecurityController extends Controller {
    /**
     * @Route("/login", name="sec_login_form")
     * @Template("DemoDemoBundle:Security:login.html.twig")
     * @Method("GET|POST")
     */
    public function loginAction()
    {  

    $auth_checker = $this->get('security.authorization_checker');

    if ( $auth_checker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')
       && !( $auth_checker->isGranted('ROLE_USER') ||  $auth_checker->isGranted('ROLE_ADMIN')  )
            ) {

        $authenticationUtils = $this->get('security.authentication_utils');
        $error = $authenticationUtils->getLastAuthenticationError();
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render (
              'DemoDemoBundle:Security:login.html.twig' ,   
            array(
            'last_username' => $lastUsername,
            'error'         => $error,
        ) );  
    } 
    else {
        return $this->render(
                'DemoDemoBundle:Default:index.html.twig',
                array('msg' => "You are already logged in!", ) ); //case of bundle
        }  
    }

    /**
     * @Route("/login_check", name="sec_login_check")
     */
    public function loginCheckAction() {
      //print_r(" there is something wrong with the firewall if you see this :loginCheckAction, route name sec_login_check");
}

    /**
     * @Route("/logout", name="sec_logout")
     */
    public function logoutAction() {}

}

// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\demo\app\config\security.yml security:

 encoders:
        Demo\DemoBundle\Entity\User: sha512

    providers:
        database_users:
            entity: 
                class: DemoDemoBundle:User 
                property: username

    role_hierarchy:
        ROLE_AUTHOR:      [ROLE_USER]

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

        secured_area:
            pattern:  ^/  , but it gives the same error
            #also used  pattern:    ^/security/  but it gives the same error
            provider: database_users 
            anonymous: ~
            access_denied_url: /security/login
            form_login:
                check_path: sec_login_check
                login_path: sec_login_form 
            logout:
                path:   sec_logout
                target: event_index

        access_control:
 #i have used only one case from below at a time:

 #case 1 gives the error: The controller must return a response (null given)
            - { path: ^/security/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/, roles: ROLE_USER }

 #case 2 gives the error: The controller must return a response (null given)
            - { path: ^/security/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/, roles: ROLE_USER }

 #case 3 gives the error: The controller must return a response (null given)
           - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

// C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\demo\app\config\routing.yml

demo_demo_security:
    resource: "@DemoDemoBundle/Controller/SecurityController.php"
    type:     annotation
    prefix:   / 

sec_login_form:
    path: /security/login
    defaults: { _controller: 'DemoDemoBundle:Security:login' }
    options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
    methods: [POST, GET]

sec_login_check:
    path: /security/login_check
    defaults: { _controller: 'DemoDemoBundle:Security:loginCheck' }
    options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
    methods: [POST, GET]

sec_logout:
    path: /security/logout
    defaults: { _controller: 'DemoDemoBundle:Security:logout' }
    options: { compiler_class: Symfony\Component\Routing\RouteCompiler } 

**************** This is a question that I asked two weeks before.

( {_trans} , - . , , , ? , |trans .

sym\just2\app\config\routing.yml

    sec_login_form:
        path: /security/login
        defaults: { _controller: 'MeetingBundle:Security:login' }
        options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
        methods: [POST, GET]

    sec_login_check:
        path: /security/login_check
        defaults: { _controller: 'MeetingBundle:Security:loginCheck' }
        options: { compiler_class: Symfony\Component\Routing\RouteCompiler }
        methods: [POST, GET]
    sec_logout:
        path: /security/logout
        defaults: { _controller: 'MeetingBundle:Security:logout' }
        options: { compiler_class: Symfony\Component\Routing\RouteCompiler }  

C:\Bitnami\wampstack-5.6.20-0\apache2\HTDOCS\\ Just2 \\Config\security.yml

   security:

        encoders:
            MeetingBundle\Entity\User: sha512

        providers:
            database_users:
                entity: { class: MeetingBundle:User }

        role_hierarchy:
            ROLE_AUTHOR:      [ROLE_USER]
            ROLE_ADMIN:       [ROLE_ADMIN]

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

            secured_area:
                pattern:    ^/  
                provider: database_users
                anonymous: true
                access_denied_url: /security/login
                form_login:
                    check_path:  /security/login_check
# did not work  either: sec_login_check
                    login_path: /security/login
# did not work  either: sec_login_form 
                    default_target_path: event_index
                    always_use_default_target_path: true
                logout:
                    path:  /security/logout
# did not work either: sec_logout
                    target: event_index

        access_control:
            - { path: ^/security/login_check$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/security/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/event/, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
            - { path: ^/evcom/, roles: IS_AUTHENTICATED_ANONYMOUSLY }  
            - { path: ^/security/regist1$, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
            - { path: ^/security/remind$, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
            - { path: ^/security/confirm$, roles: IS_AUTHENTICATED_ANONYMOUSLY  } 
            - { path: ^/security/reset$, roles: [ROLE_USER] } 
            - { path: ^/security/logout$, roles: [ROLE_USER]}
            - { path: ^/eventjoin, roles: [ROLE_USER] } 
            - { path: ^/user/, roles: [ROLE_USER] }  
            - { path: ^/event/.+, roles: [ROLE_USER] }
            - { path: ^/message/.+, roles: [ROLE_USER] }           
            - { path: ^/, roles: [ROLE_USER, ROLE_ADMIN, IS_AUTHENTICATED_ANONYMOUSLY] }
          }  

C:\Bitnami\wampstack-5.6.20-0\apache2\HTDOCS\SYM\Just2\SRC\MeetingBundle\Controller\SecurityController.php

 <?php

    namespace MeetingBundle\Controller;

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
    // use Symfony\Component\HttpFoundation\Response;


    use MeetingBundle\Entity\User;

    /** 
     * Class SecurityController
     * 
     * @Route("/security")
     * @package MeetingBundle\Controller
     */
    class SecurityController extends Controller {

    /* EXPLANATIONS about security
     * http://www.reecefowell.com/2012/04/30/authorisation-on-roles-in-symfony2/
    */

        /**
         * @Route("/login", name="sec_login_form")
         * @Template("MeetingBundle:Security:login.html.twig")
         * @Method("GET|POST")
         */
        public function loginAction()
        {  

        $auth_checker = $this->get('security.authorization_checker');

        if ( $auth_checker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')
           && !( $auth_checker->isGranted('ROLE_USER') ||  $auth_checker->isGranted('ROLE_ADMIN')  )
                ) {
            $authenticationUtils = $this->get('security.authentication_utils');
            $error = $authenticationUtils->getLastAuthenticationError();
            $lastUsername = $authenticationUtils->getLastUsername();

            return $this->render (
                  'MeetingBundle:Security:login.html.twig' ,   
                array(
                'last_username' => $lastUsername,
                'error'         => $error,
            ) );

        } 
        else {
            return $this->render(
                    'MeetingBundle:Security:msg.html.twig',
                    array('msg' => "You are already logged in!", ) ); //case of bundle
            }

        }

        /**
         * @Route("/login_check", name="sec_login_check")
         * 
         */
        public function loginCheckAction()
        {
            print_r(" there is something wrong with the firewall if you see this :loginCheckAction, route name sec_login_check");
           // return new Response();- returns, there is an empty page
        }

        /**
         * @Route("/logout", name="sec_logout")
         */
        public function logoutAction()
        {
        }

    }

C:\Bitnami\wampstack-5.6.20-0\apache2\HTDOCS\SYM\Just2\SRC\MeetingBundle\Resources\Views\Security\login.html.twig

{% extends "MeetingBundle::layoutBare.html.twig" %}

{% block stylesheets %}  {{ parent() }}  {% endblock %}
{% block header %} {{ parent() }} {% endblock %} 
{% block msg %}  {{ parent() }}   {% endblock %}  

{% block body %}

    <form action="{{ path('sec_login_check') }}" method="get" class="form" id="Security_login">

        <hr><span class="desc-large-left" > Username: </span>
        <hr><input class="topcoat-text-input" type="text" id="username" name="_username" />

        <hr><span class="desc-large-left" > Password: </span>
        <hr><input class="topcoat-text-input" type="password" id="password" name="_password"/>
        <hr><button class="topcoat-button large" type="submit"> {{ 'sec.login'|trans}} </button>

    </form>

    {% block javascripts %}   {{ parent() }}   {% endblock %}
{% endblock %}
+4
1

, loginCheckAction - :

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.');
}
0

Source: https://habr.com/ru/post/1661420/