2012-11-23 44 views
1

我開始一個新項目,使用symfony2 architercture和有用的FosUserBundle來處理我的用戶。FOSUserBundle:處理不同類型的用戶

在我的應用程序中,我有兩種不同類型的用戶,分別是:用戶和企業用戶。

我創建了一個用戶窗體(帶有嵌入窗體)。 現在我想創建一個EntrepriseForm(使用不同的嵌入式表單),但由於FosUserConfiguration只允許1個註冊表單類型,我被卡住了。

如果它可以幫助,這是我的config.yml看起來像:

fos_user: 
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel' 
firewall_name: main 
user_class: Digin\UserBundle\Entity\User 
registration: 
    confirmation: 
     from_email: # Use this node only if you don't want the global email address for the confirmation email 
      address:  [email protected] 
      sender_name: xxx 
     enabled: true # change to true for required email confirmation 
     template: FOSUserBundle:Registration:email.txt.twig 
    form: 
     type:    mybundle_user_registration 
     handler:   fos_user.registration.form.handler.default 
     name:    fos_user_registration_form 
     validation_groups: [Registration] 

約我應該怎麼做,你知道嗎?

回答

1

在你的地方,我會在你的security.yml中添加一個新的角色(記得以ROLE_開頭,symfony忽略其他角色)。然後添加監聽器InteractiveLoginListener以在不同角色上登錄後執行一些額外的重定向。然後添加JMSSecurityExtraBundle這將有助於您驗證剛剛註釋在accions和控制器的訪問:

use JMS\SecurityExtraBundle\Annotation\PreAuthorize; 

class MyService 
{ 
    /** @PreAuthorize("hasRole('A') or (hasRole('B') and hasRole('C'))") */ 
    public function secureMethod() 
    { 
     // ... 
    } 
} 

看的文檔:http://jmsyst.com/bundles/JMSSecurityExtraBundle/master/installation

相關問題