简体   繁体   中英

No route for login error with ROLE_ADMIN

I wrote a user provider and registration which works fine.

But when I change the user role from ROLE_USER to ROLE_ADMIN directly with sequel pro (it's just for testing) I'm not able to login, and get the error message:

Unable to generate a URL for the named route "login" as such route does not exist.

When I change back to ROLE_USER, the login works like a charm.

This is my 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

Do I have to define anything that I'm able to login with an user with the ROLE_ADMIN?

Let me know if you need further information.

EDIT:

this is my 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');
  }
}

I just added to security.yml

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER

and

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

but this didnt changed anything.

I dont have defined any routes in my routing.yml(thats everything in it):

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

Ok,

I just wrote the wrong route in my security.yml at login_path.

Sorry for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM