簡體   English   中英

ROLE_ADMIN沒有登錄錯誤的途徑

[英]No route for login error with ROLE_ADMIN

我寫了一個用戶提供程序和注冊,可以正常工作。

但是,當我直接使用sequel pro將用戶角色從ROLE_USER更改為ROLE_ADMIN(僅用於測試)時,我無法登錄,並收到錯誤消息:

無法生成命名路由“登錄”的URL,因為這樣的路由不存在。

當我改回ROLE_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

我是否需要定義可以使用ROLE_ADMIN與用戶登錄的任何內容?

讓我知道您是否需要更多信息。

編輯:

這是我的UserController:

/**
 * 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] }

但這並沒有改變任何東西。

我沒有在我的routing.yml中定義任何路由(即其中的所有內容):

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

好,

我在login_path的security.yml中輸入了錯誤的路由。

抱歉

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM