2013-04-08 13 views
14

उपयोगकर्ता ने FOSUserBundle के पासवर्ड रीसेट का उपयोग करके अपना पासवर्ड रीसेट करने के बाद, डिफ़ॉल्ट रूप से उसे FOSUserProfile पर रीडायरेक्ट किया गया है। मैं एक अलग मार्ग पर रीडायरेक्ट करना चाहता हूं। क्या यह संभव है और यदि हां, तो कैसे?FOSUserBundle: पासवर्ड रीसेट के बाद सफलता लक्ष्य

उत्तर

37

यह एक को रीसेट ग्राहक बनाने के द्वारा किया जा सकता है:

namespace Acme\UserBundle\EventListener; 

use FOS\UserBundle\FOSUserEvents; 
use FOS\UserBundle\Event\FormEvent; 
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 PasswordResettingListener implements EventSubscriberInterface { 
    private $router; 

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

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

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

और फिर kernel.event_subscriber टैग के साथ एक सेवा के रूप में यह दर्ज की:

# src/Acme/UserBundle/Resources/config/services.yml 
services: 
    acme_user.password_resetting: 
     class: Acme\UserBundle\EventListener\PasswordResettingListener 
     arguments: [ @router ] 
     tags: 
      - { name: kernel.event_subscriber } 
मामले में
+4

नोट: इस समाधान के लिए आपको FOS Userbundle के लिए मास्टर संस्करण का उपयोग करने की आवश्यकता है। आप रीसेट नियंत्रक को विस्तारित करके और getRedirectionUrl() विधि को बदलकर एक समान परिणाम प्राप्त कर सकते हैं। –

19

आप FOS उपयोगकर्ता प्रोफ़ाइल दृश्य का उपयोग नहीं कर रहे हैं , एक बदसूरत अभी तक आसान तरीका है:

अपने app/config/routing.yml में जोड़ें:

fos_user_profile_show: 
    path: /yourpath 
+2

आप पूर्ण यूआरएल से बेहतर, 'fos_user_profile_show' नाम के साथ अपने स्वयं के नियंत्रक में मार्ग भी घोषित कर सकते हैं। –

+2

@LouTerrailloune उपरोक्त रूटिंग कॉन्फ़िगरेशन में कोई पूर्ण यूआरएल नहीं है। ऐसा लगता है लेकिन यह संकेत है –

संबंधित मुद्दे