2012-11-23 42 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

相关问题