ZF2 ZfcUser注册重定向

时间:2015-09-02 01:56:49

标签: php redirect zend-framework2 registration zfcuser

根据这篇文章:ZfcUser Redirect to page of my choice after Registration 注册后重定向问题。从' register.post'中返回\ zend \ Http \ Response对象。事件未重定向

我正在尝试将新注册的用户重定向到自定义路由,但没有成功。 目前我正在使用自己的会员列表'如下所述:  zfcuser add user role after registration

这使我能够成功使用' register.post'事件触发器写入附加信息。 我还使用它来添加具有各自功能的新注册表单字段和过滤器

    $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'));

我设法找到了一种重定向成功登录的方法。这是由onbootStrap()中的Module.php编写的,因为我缺少服务管理器(缺乏理解如何传递它)。

$zfcAuthEvents    =  $serviceManager->get('ZfcUser\Authentication\Adapter\AdapterChain')->getEventManager();
$zfcAuthEvents->attach('authenticate.success', function($authEvent) use ($serviceManager) {

在这个回调函数中有一个块

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);
        }

因此:登录时效果很好,我可以过滤掉我需要的内容并相应地重定向。 然而,注册除了带有Gravatar和注销链接的默认/用户页面之外我无法去任何地方。 (这在我的module.config.php中也被覆盖到/ account /而不是/ user /)

我注意到在ZfCUser内有一个注册后发送: 执行

的第235行周围的ZfcUser / Controller / UserController.php
$request->setPost(new Parameters($post));
return $this->forward()->dispatch(static::CONTROLLER_NAME, array('action' => 'authenticate'));

这似乎是对注册后的身份验证进行身份验证,因此我会假设&#39; authenticate.success&#39;事件被触发(如上所述),但事实并非如此。

我的猜测&#39;是以某种方式调整/ZfcUser/Controller/UserController.php中的 $ redirect = $ this-&gt; redirectCallback; - &gt; authenticateAction()[〜第169行]

注意事项: 使用Bjyauthorise进行角色管理,使用ScnSocial进行Facebook登录。

欢迎任何有效的指针或解决方案。

0 个答案:

没有答案
相关问题