2017-01-30 5 views
0


FOSUserBundle을 사용하고있는 symfony 3 응용 프로그램을 개발 중입니다.
현재 사용자 (UserA)가 새 사용자 (userB)를 추가하고 UserA와 세션 값을 유지하기를 원합니다. FOSUser가 마지막으로 등록 된 사용자 (UserB)와 세션을 변경합니다.등록 후 같은 세션 유지 FOSUserBundle

userB를 등록한 후 세션에서 USerA를 유지하려면 어떻게해야합니까?

답변

0

해결책 :

<?php 
namespace UserBundle\EventListener; 

use FOS\UserBundle\Event\FilterUserResponseEvent; 
use FOS\UserBundle\Event\FormEvent; 
use FOS\UserBundle\Event\UserEvent; 
use FOS\UserBundle\FOSUserEvents; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\HttpFoundation\Session\SessionInterface; 
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; 


class RegistrationConfirmListener implements EventSubscriberInterface 
{ 
    private $router; 
    private $olduser; 

    private $token; 



    public function __construct(UrlGeneratorInterface $router, TokenStorage $token) 
    { 
     $this->olduser = $token->getToken()->getUser(); 
     $this->router = $router; 
     $this->token =$token; 
    } 

    /** 
    * {@inheritDoc} 
    */ 
    public static function getSubscribedEvents() 
    { 
     return array(
      FOSUserEvents::REGISTRATION_COMPLETED => 'onRegistrationCompleted' 
     ); 
    } 

    public function onRegistrationCompleted(FilterUserResponseEvent $event) 
    { 
     $response = $event->getResponse(); 
     $this->token->getToken()->setUser($this->olduser); 
     $response->setTargetUrl($this->router->generate('immobilier_dashboard')); 
    } 


} 

다른 용액을 알 수있다.