[英]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: 但是,当我直接使用sequel pro将用户角色从ROLE_USER更改为ROLE_ADMIN(仅用于测试)时,我无法登录,并收到错误消息:
Unable to generate a URL for the named route "login" as such route does not exist.
无法生成命名路由“登录”的URL,因为这样的路由不存在。
When I change back to ROLE_USER, the login works like a charm. 当我改回ROLE_USER时,登录名就像一个超级按钮。
This is my security.yml: 这是我的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? 我是否需要定义可以使用ROLE_ADMIN与用户登录的任何内容?
Let me know if you need further information. 让我知道您是否需要更多信息。
EDIT: 编辑:
this is my UserController: 这是我的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 我刚刚添加到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): 我没有在我的routing.yml中定义任何路由(即其中的所有内容):
app:
resource: "@AppBundle/Controller/"
type: annotation
Ok, 好,
I just wrote the wrong route in my security.yml at login_path. 我在login_path的security.yml中输入了错误的路由。
Sorry for that. 抱歉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.