2017-02-10 25 views
1

に応じてログインするのアクセスを制限し、私は自分の役割に応じてログインしているユーザーのために/ログインへのアクセスを制限することはsymfonyは私が初めてのsymfonyを使用しています役割

これは私のsecurityControllerある

class SecurityController extends BaseController 
私はすべてが良いBであるユーザーとしてログインしてい

{

public function renderLogin(array $data) 
{ 
    if ($this->get('security.authorization_checker')->isGranted('ROLE_USER')) { 
     return $this->redirectToRoute('covoiturage_acceuil');} 

    else if ($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { 
     return $this->redirectToRoute('admin_home');} 

    return $this->render("CovoiturageBundle:User:login.html.twig", $data); 
} 

}

私が管理者としてログインしているときにルートにリダイレクトされました(covoiturage_acceuil)

答えて

3

これは、AdminにもROLE_USERがあるためです。あなたはこの問題を解決するためにあなたの状態の順序を変更することができます。

public function renderLogin(array $data) 
{ 
    if ($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { 
     return $this->redirectToRoute('admin_home');} //verify first that it's not an admin 

    else if ($this->get('security.authorization_checker')->isGranted('ROLE_USER')) { 
     return $this->redirectToRoute('covoiturage_acceuil');} 

    return $this->render("CovoiturageBundle:User:login.html.twig", $data); 
} 

また、フランス語ではなく、「acceuil」「Accueilの」;)

+0

メルシー! "accueil"c'étaisune faute de frappe pas plus;) –

関連する問題