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

角色为_ADMIN的登录错误没有路由

胡星汉
2023-03-14

我写了一个用户提供程序和注册,效果很好。

但是,当我直接使用sequel pro将用户角色从role_user更改为role_ADMIN(仅用于测试)时,我无法登录,并收到错误消息:

无法为命名路由“登录”生成URL,因为该路由不存在。

当我切换回角色_USER时,登录就像一个符咒。

这是我的security.yml:

security:

    encoders:
        AppBundle\Entity\User:
            algorithm: bcrypt

    providers:
        users:
            entity:
                class:    AppBundle:User

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

        default:
            pattern:  ^/
            provider: users
            anonymous: ~
            form_login:
                check_path:          login_check
                login_path:          login
                default_target_path: profile_index
            logout:
                path:   logout
                target: profile_index

我是否必须定义我能够使用角色为\ u ADMIN的用户登录的任何内容?

如果您需要更多信息,请告诉我。

编辑:

这是我的用户控制器:

/**
 * Class UserController
 * @Route(path="/user")
 */
class UserController extends Controller
{
  /**
   * @Route(path="/sign-up", name="user_signup")
   * @Method({ "GET", "POST" })
   */
  public function signUpAction(Request $request)
  {
    $form = $this->createForm('registration');
    $form->handleRequest($request);

    if ($form->isValid()) {
      $user = $form->getData();

      $this->get('registration_handler')
        ->createUser($user);

      return $this->redirectToRoute('profile_index');
    }

    return $this->render('User/signUp.html.twig', array(
      'form' => $form->createView()
    ));
  }

  /**
   * @Route(path="/login", name="user_login")
   */
  public function loginAction(Request $request)
  {
    $helper = $this->get('security.authentication_utils');

    return $this->render('User/login.html.twig', array(
      'last_username' => $helper->getLastUsername(),
      'error' => $helper->getLastAuthenticationError()
    ));
  }

  /**
   * @Route("/login-check", name="login_check")
   * @Method("POST")
   */
  public function loginCheckAction()
  {
    throw new \Exception('This should never be reached!');
  }

  /**
   * @Route("/logout", name="logout")
   * @Method("GET")
   */
  public function logoutAction()
  {
    throw new \Exception('This should never be reached!');
  }

  /**
   * @Route(path="/profile", name="user_profile")
   */
  public function profileAction()
  {
    return $this->render('User/profile.html.twig');
  }
}

我刚刚添加了security.yml

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER

access_control:
    - { path: ^/user, roles: [ROLE_USER, ROLE_ADMIN] }

但这并没有改变任何事情。

我没有在我的路线中定义任何路线。yml(这就是其中的全部内容):

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

共有1个答案

屈俊远
2023-03-14

好的,

我只是在登录路径的security.yml中写错了路径。

对不起。

 类似资料:
  • 本文展示了如何根据不同的用户角色,在登录之后来重定向到不同的页面。 在 method-security项目的基础上,我们构建了一个role-base-login项目。 build.gradle 修改 build.gradle 文件,让我们的role-base-login项目成为一个新的项目。 修改内容也比较简单,修改项目名称及版本即可。 jar { baseName = 'role-bas

  • 用户已作为用户角色登录,我想以员工身份登录而不提交登录表单,但身份验证失败, 请查一下密码,帮帮我 @requestmapping(value=“/home”)public ModelAndView userHomePage(Model Model,HttpServletRequest request,HttpServletResponse response,Principal Principal

  • 登录帧 菜单框架

  • 我在symfony网站上制作了登录操作教程:http://symfony.com/doc/current/cookbook/security/form_login_setup.html 当我在表单中登录时,会出现以下错误: 这是我的保安 我的安全控制器: 单击提交按钮后的重定向是登录检查,但其中没有代码,因为symfony说:

  • 下面是我的playbook目录结构。 Ansible版本:2.7.2 python2版本:2.7.5 python3版本:3.7.1

  • WebSecurityConfiguration MyUserDetailsService 模型 我有错误的Spring启动安全登录。管理员角色登录出错。但当我登录用户角色时,它工作得很好。我不明白为什么会这样? 当我尝试以管理员身份登录时,它会重定向我页面在正文中显示此内容: 但当尝试以用户身份登录时,它可以正常工作。