2015-10-04 117 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); 
    }