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.
<?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 extends Controller {
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!", ) );
}
}
public function loginCheckAction() {
}
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
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:
- { path: ^/security/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
- { path: ^/security/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
- { 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
login_path: /security/login
default_target_path: event_index
always_use_default_target_path: true
logout:
path: /security/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 MeetingBundle\Entity\User;
class SecurityController extends Controller {
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!", ) );
}
}
public function loginCheckAction()
{
print_r(" there is something wrong with the firewall if you see this :loginCheckAction, route name sec_login_check");
}
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 %}