当前位置: 首页 > 知识库问答 >
问题:

Symfony2:登录操作教程错误->登录检查没有返回值

暨修洁
2023-03-14

我在symfony网站上制作了登录操作教程:http://symfony.com/doc/current/cookbook/security/form_login_setup.html

当我在表单中登录时,会出现以下错误:

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

这是我的保安

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 }

我的安全控制器:

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
    }
}

单击提交按钮后的重定向是登录检查,但其中没有代码,因为symfony说:路由由安全系统处理,但我收到此错误。有人能帮我吗?


共有1个答案

漆雕彬彬
2023-03-14

直接返回数组,不使用渲染方法和细枝文件名。返回数组(//用户“last\u username”输入的最后一个用户名)=

 类似资料:
  • 问题内容: 我有一个示例,尝试使用Symfony2和FOSUserBundle创建AJAX登录。我设置我自己和在我的文件。 这是课程: 这对于处理成功和失败的AJAX登录尝试都非常有用。但是,启用后-我无法通过标准表单POST方法(非AJAX)登录。我收到以下错误: 我希望自己的重写和重写仅对XmlHttpRequests(AJAX请求)执行,如果没有,则将执行交还给原始处理程序。 有没有办法做到

  • 这是我的配置: 显然,我有一个路由/后台/登录的控制器,它使用正确的输入名(_username,_password)呈现登录表单。 当我编译表单时,如果我输入了错误的用户名和密码数据,我就会正确地出现错误的凭据,但是如果我输入了正确的数据,我就会以匿名用户的身份被重定向回登录页面。 一些应用程序/日志。。。 如何在第2行看到登录成功,但当控制器重定向到安全的我获得访问拒绝(第8行) 我错在哪里?非

  • 接口说明 登录并返回token 如需调用,请访问 开发者文档 来查看详细的接口使用说明 该接口仅开放给已获取SDK的开发者 如开启https功能,请求地址的协议应改为https,如:https://www.example.com/wish3dearth/api/access/v1.0.0/getLicenseInfo API地址 POST /authcenter/api/login/v1.0.0/

  • 我想限制登录用户的登录路径, security.yml 我的登录功能: 问题是它可以工作,例如,对于/admin,只有ROLE\u admin有访问权限,ROLE\u用户号。但是/login,如果我登录或不登录,我可以访问它,在symfony2开发工具中,我看到我是匿名的,我登录了stel。。。我没有主意

  • 背景:显然,我对cognito了解不多,因为我花了两个小时试图用cognito对我的用户进行身份验证,并意识到他们不是身份验证提供者,而是凭证的组织者。然后我想到了一个更简单的解决方法,而不是创建一个全新的后端来验证用户和证书希望验证其可行性。 计划:我在想,我会让用户进入我的应用程序,并以未经身份验证的用户身份自动通过Cognito的身份验证。然后我将使用对AWS Lambda和Dynamodb

  • 本文向大家介绍Vue设置长时间未操作登录自动到期返回登录页,包括了Vue设置长时间未操作登录自动到期返回登录页的使用技巧和注意事项,需要的朋友参考一下 Vue设置长时间未操作登录以后自动到期返回登录页 首先我们写在main.js文件中 我们会在登陆成功后调用sessionUtil文件中的setSession,sessionUtil下面写的有 在routerutil.js文件中 在sessionut