2013-07-29 2 views
2

처음으로 정기적으로 사용하는이 포럼에 처음으로 메시지를 게시하고 있습니다. Symfony2 애플리케이션에서 FOSUserbundle을 사용하여 사용자를 관리합니다. 그것은 아주 잘 작동Symfony2 : 등록 후 이메일 확인

fos_user: 
    registration: 
     confirmation: 
      enabled: true 

: 사용자가 다음과 같은 점에서 계정을 만들 때이 확인 이메일의 전송을 활성화 이메일이 성공적으로 전송됩니다. 이 이메일을 보냈다고 말하는 페이지/수표 이메일로 리디렉션되었습니다. 그러나 리디렉션을 변경하고 싶습니다./check-email이 아닌 내 인덱스 페이지로 리디렉션되고 싶습니다. 그래서 나는 내 연구를했고 그는 FOSUserBundle 이벤트 (list here)를 거쳐야만한다는 것을 알고있었습니다.

내가 무슨 짓을 :

class RegistrationListener implements EventSubscriberInterface { 

private $router; 

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

public static function getSubscribedEvents() { 
    return array(
      FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm'); 
} 

public function onRegistrationConfirm(FormEvent $event) { 
    $url = $this->router->generate('listeArticlesAccueil'); 
    $event->setResponse(new RedirectResponse($url)); 
} 

}

및 services.yml

services: 
    listener_user.registration_listener: 
     class: My\Soft\UserBundle\EventListener\RegistrationListener 
     arguments: [@router] 
     tags: 
      - { name: kernel.event_subscriber } 

문제는 그 내가 페이지/체크 이메일로 리디렉션하고 때마다. 그러므로 나는 그것이 아마 잘못된 사건이라고 말했다. 그래서 나는 또한 REGISTRATION_SUCCESS를 시도했다. 그러나 아무것도 바뀌지 않습니다. 그래서 나는 올바른 사건을 사용하지 않았거나 잘못된 행동을하고 있습니다.

두 경우 모두 나를 도울 수 있기를 바랍니다.

고마워요 내 나쁜 영어 죄송합니다)

답변

0

내가 REGISTRATION_SUCCESS에 내기 것입니다. 의사 (https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/FOSUserEvents.php)는이 이벤트로 응답을 설정할 수있는 이라고 말합니다. REGISTRATION_CONFIRM은 사용자에게만 액세스하도록 허용합니다.

+0

다음은 이벤트 리스너의 전체 코드입니다! REGISTRATION_SUCCESS로 시도했습니다. 전자 메일 확인을 활성화하지 않으면 내 페이지로 올바르게 리디렉션됩니다. 하지만 확인 (파일 config.yml)을 활성화하면/check-email로 리디렉션됩니다 ... 이유를 모르겠습니다! – user2630477

+0

SdZ 웹 사이트 확인 :) – Pierrito

0

대신 REGISTRATION_CONFIRM을 사용하십시오. Services.yml를 들어

/** 
* Description of RegisterationConfirmListener 
* 
* @author imran 
*/ 
use FOS\UserBundle\FOSUserEvents; 
use FOS\UserBundle\Event\GetResponseUserEvent; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 

/** 
* Description of RegisterationConfirmListener 
* 
* @author imran 
*/ 
use FOS\UserBundle\FOSUserEvents; 
use FOS\UserBundle\Event\GetResponseUserEvent; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 

/** 
* Listener responsible to change the redirection at the end of the password resetting 
*/ 
class RegisterationConfirmListener implements EventSubscriberInterface { 
    private $router; 

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

    public static function getSubscribedEvents() { 
     return [ 
      FOSUserEvents::REGISTRATION_CONFIRM => 'onRegisterationConfirm', 
     ]; 
    } 

    public function onRegisterationConfirm(GetResponseUserEvent $event) { 
     $url = $this->router->generate('home'); 
     $event->setResponse(new RedirectResponse($url)); 
    } 
} 

: 네 말이 맞아

app_user.registeration_confirmed: 
    class: Wishlocker\AppBundle\EventListener\RegisterationConfirmListener 
    arguments: [ @router ] 
    tags: 
     - { name: kernel.event_subscriber }