2015-10-04 75 views
1

我用UserBundle和HWIO社交网络,但如果用户没有社交活动,创建自定义的注册,当用户有电子邮件地址和密码的电子邮件,我尝试验证,但有许多错误的最后一个错误:Symfony的安全注册和认证

Error: User account is disabled. 

我不知道如何成为调service.yml和HWIO仍然工作和非标准认证帮助,请 ,知道不工作与HWIO输入:

Unable to find the controller for path "/login/check-vkontakte". The route is wrongly configured. 

这项工作安全性好:

security: 
encoders: 
    FOS\UserBundle\Model\UserInterface: sha512 

role_hierarchy: 
    ROLE_ADMIN:  ROLE_USER 
    ROLE_SUPER_ADMIN: ROLE_ADMIN 

providers: 
    fos_userbundle: 
     id: fos_user.user_provider.username 
    my_custom_hwi_provider: 
     id: app.provider.user_provider 


firewalls: 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 

    main: 
     pattern: ^/ 
     form_login: 
      provider: fos_userbundle 
      csrf_provider: form.csrf_provider 
     oauth: 
      resource_owners: 
       facebook:   "/login/check-facebook" 
       vkontakte:    "/login/check-vkontakte" 

      login_path:  /login 
      failure_path:  /login 

      oauth_user_provider: 
       #this is my custom user provider, created from FOSUBUserProvider - will manage the 
       #automatic user registration on your site, with data from the provider (facebook. google, etc.) 
       service: app.provider.user_provider 

     logout:  true 
     anonymous: true 

    login: 
     pattern: ^/login$ 
     security: false 

     remember_me: 
      key: "%secret%" 
      lifetime: 60 # 365 days in seconds 
      path:/
      domain: ~ # Defaults to the current domain from $_SERVER 

access_control: 
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/admin/, role: ROLE_ADMIN } 

这是我的安全

security: 
encoders: 
    FOS\UserBundle\Model\UserInterface: sha512 
    PillsBundle\Entity\User: 
     algorithm:  sha1 
     encode_as_base64: false 
     iterations:  1 
    Symfony\Component\Security\Core\User\User: plaintext 

role_hierarchy: 
    ROLE_ADMIN:  ROLE_USER 
    ROLE_SUPER_ADMIN: ROLE_ADMIN 

providers: 
    fos_userbundle: 
     id: fos_user.user_provider.username 
    my_custom_hwi_provider: 
     id: app.provider.user_provider 

    chain_provider: 
     chain: 
      providers: [user_db, in_memory] 
    user_db: 
     entity: { class: UserBundle\Entity\User, property: email } 
    in_memory: 
     memory: 
     users: 
      admin_tyty: { password: adminpass_tyty, roles: [ 'ROLE_ADMIN' ] } 


firewalls: 

    admin_secured_area: 
     pattern: /(.*) 
     anonymous: ~ 
     form_login: 
      provider: chain_provider 
      login_path: /auth/login 
      check_path: /auth/login_check 
      always_use_default_target_path: true 
      default_target_path: /?r=db 
     logout: 
      path: /auth/logout 
      target:/
      invalidate_session: false 


    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 

    main: 
     pattern: ^/ 
     form_login: 
      provider: fos_userbundle 
      #csrf_provider: form.csrf_provider 
     oauth: 
      resource_owners: 
       facebook:   "/login/check-facebook" 
       vkontakte:    "/login/check-vkontakte" 

      login_path:  /login 
      failure_path:  /login 

      oauth_user_provider: 
       #this is my custom user provider, created from FOSUBUserProvider - will manage the 
       #automatic user registration on your site, with data from the provider (facebook. google, etc.) 
       service: app.provider.user_provider 

     logout:  true 
     anonymous: true 

    login: 
     pattern: ^/login$ 
     security: false 

     remember_me: 
      key: "%secret%" 
      lifetime: 60 # 365 days in seconds 
      path:/
      domain: ~ # Defaults to the current domain from $_SERVER 

access_control: 
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/admin/, role: ROLE_ADMIN } 

和我SecurityController控制器

/** 
    * @Route("/auth") 
    */ 
class SecurityController extends Controller 
{ 
/** 
* @Route("/login", name="login_route") 
* @Template() 
*/ 
public function loginAction() 
{ 
    $request = $this->getRequest(); 
    $session = $request->getSession(); 

    $securityContext = $this->container->get('security.context'); 
    if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) { 
     return $this->redirect($this->generateUrl('get_all_posts')); 
    } 

    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { 
     $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); 
    } else { 
     $error = $session->get(SecurityContext::AUTHENTICATION_ERROR); 
     $session->remove(SecurityContext::AUTHENTICATION_ERROR); 
    } 

    return array(
     '_last' => $session->get(SecurityContext::LAST_USERNAME), 
     'error'   => $error, 
    ); 
} 

回答

0

如果你有重写登记控制器然后就启用FOSUserBundle用户>这个RegistrationController类

如果没有然后看看这个文档。 http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html

RegistrationController extends BaseController 
{ 
    public function registerAction(Request $request) 
    { 
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ 
     $formFactory = $this->get('fos_user.registration.form.factory'); 
     /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ 
     $userManager = $this->get('fos_user.user_manager'); 
    /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ 
     $dispatcher = $this->get('event_dispatcher'); 

     $user = $userManager->createUser(); 
     $user->setEnabled(true); 
    }