第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Symfony 4 安全重定向取決于用戶類型

Symfony 4 安全重定向取決于用戶類型

PHP
翻閱古今 2023-07-08 20:55:28
我正在一個網(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.

    }

}


查看完整回答
反對 回復(fù) 2023-07-08
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號