Based on this post: ZfcUser Redirect to page of my choice after Registration Trouble with redirection after registration. Returning a \zend\Http\Response object from the 'register.post' event does not redirect
I am trying to redirect a newly registered user to a custom route without success. Currently I'm using my own 'MemberListner' as described here: zfcuser add user role after registration
This allows me to successfully use the 'register.post' event trigger to write additional information. I've also used this to add new registration form fields and filters with their own respective functions
$this->listeners[] = $sharedManager->attach('ZfcUser\Service\User', 'register', array($this, 'onRegister'));
$this->listeners[] = $sharedManager->attach('ZfcUser\Service\User', 'register.post', array($this, 'onRegisterPost'));
// SCN Social Auth did not register the link. Need to add here too.
$this->listeners[] = $sharedManager->attach('ScnSocialAuth\Authentication\Adapter\HybridAuth', 'registerViaProvider.post', array($this,'onSocialRegisterPost'));
// Currently run within the module due to lack of service manager on authentication
$this->listeners[] = $sharedManager->attach('ZfcUser\Authentication\Adapter\AdapterChain', 'authenticate.success', array($this, 'onAuthenticateSuccess'));
I have managed to find a way to redirect on successful login. This is written in Module.php in onBootStrap() due to my lack of a service manager (lack of understanding how to pass it around).
$zfcAuthEvents = $serviceManager->get('ZfcUser\Authentication\Adapter\AdapterChain')->getEventManager();
$zfcAuthEvents->attach('authenticate.success', function($authEvent) use ($serviceManager) {
Within this callback function there is a block
if ($member->getStatus() != 'COMPLETE') {
// we are going to re-set service,
// we need to set allow_override of serviceManager= true
$serviceManager->setAllowOverride(true);
$zfcuserModuleOptions = $serviceManager->get('zfcuser_module_options');
$zfcuserModuleOptions->setLoginRedirectRoute('member-register',array('action'=>'<My-Custom-Action>'));
$serviceManager->setService('zfcuser_module_options', $zfcuserModuleOptions);
// set 'allow_override' back to false
$serviceManager->setAllowOverride(false);
}
Therefore: On login this works great and I can filter out what I need and redirect accordingly. The registration however I cannot get to go anywhere except the default /user page with the Gravatar and logout link. (This is also overwritten in my module.config.php to /account/ and not /user/)
I've noticed that within ZfCUser there is a dispatch after registration: ZfcUser/Controller/UserController.php around line 235 performing
$request->setPost(new Parameters($post));
return $this->forward()->dispatch(static::CONTROLLER_NAME, array('action' => 'authenticate'));
This appears to authenticate post registration and so I would assume the 'authenticate.success' event is triggered (as described above) but it's not.
My 'guess' is to somehow adjust the $redirect = $this->redirectCallback; in the /ZfcUser/Controller/UserController.php -> authenticateAction() [~line 169]
Points to note: Using Bjyauthorise for role management, ScnSocial for Facebook login.
Any pointers or solutions that have worked are welcome.