1

I want to forward unauthenticated request to ZfcUser login action, then redirect to original request after successful login.

I have this code inside my controller action;

// Check we are logged in.
if (!$this->zfcUserAuthentication()->hasIdentity()) {

    // Set the 'redirect' parameter
    $redirect = $this->getRequest()->getRequestUri();
    $this->getRequest()->getQuery()->set('redirect', $redirect);

    // Forward request to zfcUser's login action.
    return $this->forward()->dispatch('zfcuser', array(
        'action' => 'login'
    ));
}

I have un-commented this line in the ZfcUser config;

'use_redirect_parameter_if_present' => true,

It does forward to the ZfcUser login action preserving original url, but it does not redirect back to original requested page after login.

Any ideas on what could be wrong?

srayner
  • 1,799
  • 4
  • 23
  • 39

2 Answers2

1

Note that you have to pass a route as the redirect param, not an URI. If you want to use an URL, take a look at this module: https://github.com/Eye4web/E4WZfcUserRedirectUrl

Danielss89
  • 863
  • 1
  • 11
  • 17
0

I was overriding the default views with my own. In my view i missed the redirect hidden form element.

Adding the hidden redirect form element solved the redirect problem.

I am also using an old version of ZfcUser, and I believe this feature may have changed between versions.

srayner
  • 1,799
  • 4
  • 23
  • 39