2017-04-22 62 views
0

我使用PUGXMultiUserBundle 我想有2個系統中的用戶(管理客戶端) 現在我希望能有獨立的管理面板,併成功登錄後的不同重定向剛剛起步,註冊等。如何設置防火牆與PUGXMultiUserBundle在security.yml

我不應該能夠在我的security.yml中基於用戶歧視來設置防火牆嗎?

現在我按照指示,想出瞭如何構建註冊表單,並將我的用戶分開。 當註冊完成後我得到了證實網址

There is no user provider for user "AppBundle\Entity\CabAgencyUser".

回答

0

對不起,我的英文不好的錯誤,但您的解決方案可能是:

聲明兩個服務,像這樣的應用程序/配置/服務.yml或一些其它service.yml任何束的內部(的appbundle例如):

app_user_security.component.authentication.handler.login_success_handler: 
    class: AdminBundle\Component\Authentication\Handler\LoginSuccessHandler 
    arguments: [@router, @security.context] 
    tags: 
     - { name: 'monolog.logger', channel: 'security' } 

app_user_security.component.authentication.handler.logout_success_handler: 
    class: AdminBundle\Component\Authentication\Handler\LogoutSuccessHandler 
    arguments: [@router] 
    tags: 
     - { name: 'monolog.logger', channel: 'security' } 

接着創建兩個類是這樣的:

<?php 

/** 
* Handler for users Login 
*/ 

namespace AdminBundle\Component\Authentication\Handler; 

use Symfony\Component\HttpFoundation\Cookie; 
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; 
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
use Symfony\Component\Security\Core\SecurityContext; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use BeSimple\I18nRoutingBundle\Routing\Router; 

class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface { 

    protected $router; 
    protected $security; 

    function __construct(Router $router, SecurityContext $security) 
    { 
    $this->router = $router; 
    $this->security = $security; 
    } 

    public function onAuthenticationSuccess(Request $request, TokenInterface $token) 
    { 
    $session = $request->getSession(); 
    $obj = array(); 
    $obj['name'] = $token->getUser()->__toString(); 
    $obj['username'] = $token->getUsername(); 

    $session->set('last_login_user', $obj); 

    if ($this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMINISTRADOR')) 
    { 
     $referer_url = $this->router->generate('admin_dashboard'); 
    } 
    elseif($this->security->isGranted('ROLE_USUARIO') || $this->security->isGranted('ROLE_USUARIO_SOCIAL')) { 
     $referer_url = $this->router->generate('app_frontend_dashboard', array(
      //'slug' => $token->getUser()->getSlug() 
    )); 
    } else { 
     $referer_url = $this->router->generate('app_frontend_dashboard'); 
    } 

    $cookie = new Cookie('last_login_user', serialize($token->getUser()), time()+(3600*48)); 

    $response = new RedirectResponse($referer_url); 
    $response->headers->setCookie($cookie); 

    return $response; 
    } 


} 

這:

<?php 

    /** 
    * Handler for logout... 
    */ 

    namespace AdminBundle\Component\Authentication\Handler; 

    use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface; 
    use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
    use Symfony\Component\HttpFoundation\Request; 
    use Symfony\Component\HttpFoundation\RedirectResponse; 
    use BeSimple\I18nRoutingBundle\Routing\Router; 

    class LogoutSuccessHandler implements LogoutSuccessHandlerInterface { 

     protected $router; 

     public function __construct(Router $router) 
     { 
     $this->router = $router; 
     } 

     public function onLogoutSuccess(Request $request) 
     { 
     // redirect the user to where they were before the login process begun. 
     //$referer_url = $request->headers->get('referer'); 
     //$response = new RedirectResponse($referer_url); 

      $referer_url = $this->router->generate('app_frontend_homepage'); 
      $response = new RedirectResponse($referer_url); 

      return $response; 
     } 
    } 

好陸先生!

我解決任何用戶提供的問題鏈供應商是這樣的:

//security.yml 

security: 

    encoders: 
     #FOS\UserBundle\Model\UserInterface: bcrypt 
     FOS\UserBundle\Model\UserInterface: sha512 

    role_hierarchy: 
     ROLE_ADMINISTRADOR:   [ROLE_USUARIO, ROLE_USUARIO_SOCIAL] 
     ROLE_SUPER_ADMINISTRADOR: ROLE_ADMINISTRADOR 

    # http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded 
    providers: 
     chain_provider: 
      chain: 
       providers: [in_memory, fos_userbundle, user_db_username, user_db_email] 
     in_memory: 
      memory: ~ 
     fos_userbundle: 
      id: fos_user.user_provider.username_email 
     user_db_username: 
      entity: { class: AdminBundle\Entity\UsuarioBase, property: username } 
     user_db_email: 
      entity: { class: AdminBundle\Entity\UsuarioBase, property: email } 

我覺得剛纔爲什麼有FOSUserBundle和PUXMultiuserBundle不相容一定程度上,一些認爲前工作時間,現在是碎米!

+0

我打算,並希望它會好的:D,但我認爲這是問題的基礎,每個人都有一個小的差異,使現成的捆綁麻煩。 – alexseif