我正在一個網(wǎng)站上工作,該網(wǎng)站將有兩種類型的用戶“客戶”(客戶)和“雇員”(雇員)這兩個類都擴(kuò)展了我的用戶類:我的客戶班/** * @ORM\Entity(repositoryClass="App\Repository\ClientRepository") */class Client extends User{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ protected $id; /** * @ORM\Column(type="string", length=255) */ private $client_fonction; /** * @ORM\OneToMany(targetEntity="App\Entity\ClientEmployee", mappedBy="client_id") */ private $client_id; /** * @ORM\ManyToOne(targetEntity=Site::class, inversedBy="clients") */ private $site;我的員工班級/** * @ORM\Entity(repositoryClass="App\Repository\EmployeRepository") */class Employe extends User{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ protected $id; /** * @ORM\Column(type="integer", nullable=true) */ private $portablePro; /** * @ORM\ManyToOne(targetEntity="App\Entity\Agence", inversedBy="agence_id") * @ORM\JoinColumn(nullable=false) */ private $agence_spie_id; /** * @ORM\OneToMany(targetEntity="App\Entity\ClientEmployee", mappedBy="employe_id") */ private $employe_id;這是我的 User 類中的繼承映射:/** * @ORM\Entity(repositoryClass=UserRepository::class) * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap({"Employe"="Employe", "Client"="Client"}) */abstract class User implements UserInterface我正在尋找方法:如果用戶是“客戶”-> 重定向到 /client 路由 如果用戶是“雇員”-> 重定向到 /admin 路由。在我的 security.yaml 中,我設(shè)置了 2 個提供程序:providers: chain_provider: chain: providers: [app_employe_provider, app_client_provider] app_employe_provider: entity: class: App\Entity\EmployeSpie property: email app_client_provider: entity: class: App\Entity\Client property: email如何在我的 LoginFormAuthenticator 中,我可以根據(jù)用戶的類型重定向用戶?
1 回答

郎朗坤
TA貢獻(xiàn)1921條經(jīng)驗 獲得超9個贊
由于令牌作為參數(shù)傳遞,您可以從那里提取用戶(類型)。
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
$user = $token->getUser();
if($user instanceof Employe) {
// Do one thing
} else if($user instanceof Client){
// Do other thing.
}
}
- 1 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消