Quantcast

Referer

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Referer

Jigal Sanders
Hello,

This is more of an architectual question which should lead for me to a
development decision.
I sometimes in my application have some links. But in order to see what's
behind the links you have to be logged in. So the user is redirected to a
login page.
But I want the user to be redirected to the original page after he has
logged in.

What's the best way to implement this in a zf based site?

Looking forward to your suggestions and links to existing tutorials.

J. Sanders
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

weierophinney
Administrator
-- Jigal sanders <[hidden email]> wrote
(on Friday, 22 October 2010, 04:48 PM +0200):
> This is more of an architectual question which should lead for me to a
> development decision.
> I sometimes in my application have some links. But in order to see what's
> behind the links you have to be logged in. So the user is redirected to a
> login page.
> But I want the user to be redirected to the original page after he has
> logged in.
>
> What's the best way to implement this in a zf based site?

Grab the referer from the request object:

    // In an action method of a controller
    $request = $this->getRequest();
    if (/* some op succeeded */) {
        $origin = $request->getHeader('referer');
        return $this->_redirect($origin);
    }

That's really all there is to it.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Jigal Sanders
Well from user/edit i am redirected to user/login

In the login action i do:

$origin = $this->request()->getHeader('referer');
var_dump($origin);

And it gives me:

index/index

But i expect

user/edit

On Fri, Oct 22, 2010 at 4:58 PM, Matthew Weier O'Phinney
<[hidden email]>wrote:

> -- Jigal sanders <[hidden email]> wrote
> (on Friday, 22 October 2010, 04:48 PM +0200):
> > This is more of an architectual question which should lead for me to a
> > development decision.
> > I sometimes in my application have some links. But in order to see what's
> > behind the links you have to be logged in. So the user is redirected to a
> > login page.
> > But I want the user to be redirected to the original page after he has
> > logged in.
> >
> > What's the best way to implement this in a zf based site?
>
> Grab the referer from the request object:
>
>    // In an action method of a controller
>    $request = $this->getRequest();
>    if (/* some op succeeded */) {
>        $origin = $request->getHeader('referer');
>        return $this->_redirect($origin);
>    }
>
> That's really all there is to it.
>
> --
> Matthew Weier O'Phinney
> Project Lead            | [hidden email]
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

weierophinney
Administrator
In reply to this post by weierophinney
-- Matthew Weier O'Phinney <[hidden email]> wrote
(on Friday, 22 October 2010, 10:58 AM -0400):

> -- Jigal sanders <[hidden email]> wrote
> (on Friday, 22 October 2010, 04:48 PM +0200):
> > This is more of an architectual question which should lead for me to a
> > development decision.
> > I sometimes in my application have some links. But in order to see what's
> > behind the links you have to be logged in. So the user is redirected to a
> > login page.
> > But I want the user to be redirected to the original page after he has
> > logged in.
> >
> > What's the best way to implement this in a zf based site?
>
> Grab the referer from the request object:
>
>     // In an action method of a controller
>     $request = $this->getRequest();
>     if (/* some op succeeded */) {
>         $origin = $request->getHeader('referer');
>         return $this->_redirect($origin);
>     }
>
> That's really all there is to it.

One thing: somebody asked me to point out that you shouldn't blindly
trust the Referer header, which is an excellent point to make. Run it
through a regexp, and ensure it's actually heading back to *your* site.
:)

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

weierophinney
Administrator
In reply to this post by Jigal Sanders
-- Jigal sanders <[hidden email]> wrote
(on Friday, 22 October 2010, 05:12 PM +0200):

> Well from user/edit i am redirected to user/login
>
> In the login action i do:
>
> $origin = $this->request()->getHeader('referer');
> var_dump($origin);
>
> And it gives me:
>
> index/index
>
> But i expect
>
> user/edit

Ooops, my bad; you need to store the page that sent you to the login
form:

    // on login page:
    $referer = $this->getRequest()->getHeader('referer');
    // don't forget to sanitize the referer and ensure it goes to a page
    // on your site!

    $session = new Zend_Session_Namespace('login');
    $session->referer = $referer;

Then, after successful login:

    $session = new Zend_Session_Namespace('login');
    $referer = $session->referer;
    if (empty($referer)) {
        $referer = /* some default page */;
    }
    return $this->_redirect($referer);

> On Fri, Oct 22, 2010 at 4:58 PM, Matthew Weier O'Phinney
> <[hidden email]>wrote:
>
> > -- Jigal sanders <[hidden email]> wrote
> > (on Friday, 22 October 2010, 04:48 PM +0200):
> > > This is more of an architectual question which should lead for me to a
> > > development decision.
> > > I sometimes in my application have some links. But in order to see what's
> > > behind the links you have to be logged in. So the user is redirected to a
> > > login page.
> > > But I want the user to be redirected to the original page after he has
> > > logged in.
> > >
> > > What's the best way to implement this in a zf based site?
> >
> > Grab the referer from the request object:
> >
> >    // In an action method of a controller
> >    $request = $this->getRequest();
> >    if (/* some op succeeded */) {
> >        $origin = $request->getHeader('referer');
> >        return $this->_redirect($origin);
> >    }
> >
> > That's really all there is to it.
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead            | [hidden email]
> > Zend Framework          | http://framework.zend.com/
> > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
> >
>
>
>
> --
> Met vriendelijke groet,
>
> Jigal Sanders
> A.J. Ernststraat 739
> 1082 LK Amsterdam
> Mobiel: 06-42111489

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Hector Virgen
You can avoid the referrer if you keep track of the current page before
redirecting to login. Once of the solutions I've used goes a little
something like this:

// on page that needs login
$session = new Zend_Session_Namespace('login');
$session->gotoAfterLogin = $this->_request->getRequestUri();
return $this->_redirect('login');

// on successful login
$session = new Zend_Session_Namespace('login');
if (isset($session->gotoAfterLogin)) {
    $gotoAfterLogin = $session->gotoAfterLogin;
    unset($session->gotoAfterLogin);
    return $this->_redirect($gotoAfterLogin);
}
return $this->_redirect('/');

To avoid copy/pasting that first bit of code in all of your controllers you
can move it to an action helper. Also note the unset() prior to the redirect
-- if the user logs out and back in you don't want that redirect to occur
again.

--
*Hector Virgen*
Sr. Web Developer
Walt Disney Parks and Resorts Online
http://www.virgentech.com
--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Jigal Sanders
Hello,

With some help I have created the action helper below, but i don't know when
to call the saveOriginalUrl function:



<?php
class SF_Controller_Action_Helper_Referrer extends
Zend_Controller_Action_Helper_Abstract
{
    public function saveOriginalUrl(){
        $session = new Zend_Session_Namespace('login');
        $request = $this->getRequest();
        $session->goToAfterLogin = array(
           $request->getActionName(),
           $request->getControllerName(),
           $request->getModuleName(),

        );
        return $this->_getRedirect()->gotoSimple('login','user','eventManager');
    }

    public function getOriginalUrl(){
        $session = new Zend_Session_Namespace('login');
        if(isset($session->goToAfterLogin)){
            $gotoAfterLogin = $session->goToAfterLogin;
            unset($session->goToAfterLogin);
            return $this->_getRedirect->gotoSimple($gotoAfterLogin);
        }
        return $this->_getRedirect()->gotoUrl('/');
    }

    protected function _getRedirect(){
       return Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
    }
}


On Fri, Oct 22, 2010 at 7:12 PM, Hector Virgen <[hidden email]> wrote:

> You can avoid the referrer if you keep track of the current page before
> redirecting to login. Once of the solutions I've used goes a little
> something like this:
>
> // on page that needs login
> $session = new Zend_Session_Namespace('login');
> $session->gotoAfterLogin = $this->_request->getRequestUri();
> return $this->_redirect('login');
>
> // on successful login
> $session = new Zend_Session_Namespace('login');
> if (isset($session->gotoAfterLogin)) {
>    $gotoAfterLogin = $session->gotoAfterLogin;
>    unset($session->gotoAfterLogin);
>    return $this->_redirect($gotoAfterLogin);
> }
> return $this->_redirect('/');
>
> To avoid copy/pasting that first bit of code in all of your controllers you
> can move it to an action helper. Also note the unset() prior to the
> redirect
> -- if the user logs out and back in you don't want that redirect to occur
> again.
>
> --
> *Hector Virgen*
> Sr. Web Developer
> Walt Disney Parks and Resorts Online
> http://www.virgentech.com
>



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Jigal Sanders
Little push.

Any idea's?

On Sun, Oct 24, 2010 at 9:52 AM, Jigal sanders <[hidden email]>wrote:

> Hello,
>
> With some help I have created the action helper below, but i don't know
> when to call the saveOriginalUrl function:
>
>
> <?php
> class SF_Controller_Action_Helper_Referrer extends Zend_Controller_Action_Helper_Abstract
> {
>     public function saveOriginalUrl(){
>         $session = new Zend_Session_Namespace('login');
>         $request = $this->getRequest();
>         $session->goToAfterLogin = array(
>            $request->getActionName(),
>            $request->getControllerName(),
>            $request->getModuleName(),
>
>         );
>         return $this->_getRedirect()->gotoSimple('login','user','eventManager');
>     }
>
>     public function getOriginalUrl(){
>         $session = new Zend_Session_Namespace('login');
>         if(isset($session->goToAfterLogin)){
>             $gotoAfterLogin = $session->goToAfterLogin;
>             unset($session->goToAfterLogin);
>             return $this->_getRedirect->gotoSimple($gotoAfterLogin);
>         }
>         return $this->_getRedirect()->gotoUrl('/');
>     }
>
>     protected function _getRedirect(){
>        return Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
>     }
> }
>
>
> On Fri, Oct 22, 2010 at 7:12 PM, Hector Virgen <[hidden email]> wrote:
>
>> You can avoid the referrer if you keep track of the current page before
>> redirecting to login. Once of the solutions I've used goes a little
>> something like this:
>>
>> // on page that needs login
>> $session = new Zend_Session_Namespace('login');
>> $session->gotoAfterLogin = $this->_request->getRequestUri();
>> return $this->_redirect('login');
>>
>> // on successful login
>> $session = new Zend_Session_Namespace('login');
>> if (isset($session->gotoAfterLogin)) {
>>    $gotoAfterLogin = $session->gotoAfterLogin;
>>    unset($session->gotoAfterLogin);
>>    return $this->_redirect($gotoAfterLogin);
>> }
>> return $this->_redirect('/');
>>
>> To avoid copy/pasting that first bit of code in all of your controllers
>> you
>> can move it to an action helper. Also note the unset() prior to the
>> redirect
>> -- if the user logs out and back in you don't want that redirect to occur
>> again.
>>
>> --
>> *Hector Virgen*
>> Sr. Web Developer
>> Walt Disney Parks and Resorts Online
>> http://www.virgentech.com
>>
>
>
>
> --
> Met vriendelijke groet,
>
> Jigal Sanders
> A.J. Ernststraat 739
> 1082 LK Amsterdam
> Mobiel: 06-42111489
>



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Jigal Sanders
In reply to this post by Jigal Sanders
Hi,

Thanks for your reply.
But then I have to call it in each controller. shouldn't it be called in a
kind of pre-dispach loop?

On Mon, Oct 25, 2010 at 10:11 AM, Jean-Sébastien H.
<[hidden email]>wrote:

> Hi,
>
> You should call saveOriginalUrl before the redirection.
>
> PS : FlashMessenger action helper can help you to store the URL
>
>
> http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.flashmessenger.introduction
>
> On Sun, 24 Oct 2010 09:52:51 +0200, Jigal sanders
> <[hidden email]> wrote:
> > Hello,
> >
> > With some help I have created the action helper below, but i don't know
> when
> > to call the saveOriginalUrl function:
> >
> >
>
>
> --
> Jean-Sébastien H.
> au-fil-du.net
>



--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

localheinz
In reply to this post by Jigal Sanders
That's what a plugin is supposed to be for.


Best regards,

Andreas

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Jigal Sanders
Right so where should i call my saveOriginalUrl

On Mon, Oct 25, 2010 at 10:52 AM, Andreas Möller <[hidden email]> wrote:

> That's what a plugin is supposed to be for.
>
>
> Best regards,
>
> Andreas
>
>


--
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

localheinz
In reply to this post by Jigal Sanders
In the plugin's predispatch method you perform your check whether the current consumer has authenticated and has privileges for the desired action - if he doesn't, you save the requested url and either

a) modify the request object so the request will be dispatched to your login action

or

b) you redirect to the login action.


Best regards,

Andreas

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Wil Moore III
Some good ideas have been thrown out here...I have a slightly different method which seems much simpler than utilizing Session. I'm about to board a plane so I'll be brief. If you need code for a specific piece, post back and I'll set you up:


1 - Write a front-controller plug-in and hook into routeShutdown
     NOTE: I haven't seen any good reason to wait any longer than routeShutdown (if anyone has contrary feedback, I'd be interested in knowing about it)
2 - bail-out early if already logged in (return;)
3 - if the requested resource is not secured, bail-out (return;)
4 - switch the resource by manually setting module, controller, and action
5 - set a request parameter
     Example: $request->setParam('onAuthenticateGoto', $request->getPathInfo());
6 - return the request object


Good luck. Let me know if you need a pastie.

                       
--
Wil Moore III

Best Practices for Working with Open-Source Developers
http://www.faqs.org/docs/artu/ch19s02.html

Why is Bottom-posting better than Top-posting:
http://www.caliburn.nl/topposting.html

DO NOT TOP-POST and DO trim your replies:
http://linux.sgms-centre.com/misc/netiquette.php#toppost
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Hector Virgen
Thanks for the tip, Wil. A pastie would be nice (your plane has wi-fi,
right?) :)

Does your solution cover the use case where a user enters in the wrong
password on the first attempt but gets it right on the second attempt (or
later)?

--
*Hector Virgen*
Sr. Web Developer
Walt Disney Parks and Resorts Online
http://www.virgentech.com
--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Jigal Sanders
Yeah please send a pastie

On 26 okt. 2010, at 01:09, Hector Virgen <[hidden email]> wrote:

> Thanks for the tip, Wil. A pastie would be nice (your plane has wi-fi,
> right?) :)
>
> Does your solution cover the use case where a user enters in the wrong
> password on the first attempt but gets it right on the second attempt (or
> later)?
>
> --
> *Hector Virgen*
> Sr. Web Developer
> Walt Disney Parks and Resorts Online
> http://www.virgentech.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Peter Schaefer
This post has NOT been accepted by the mailing list yet.
In reply to this post by Wil Moore III
Wil,

I am currently in the process of writing a re-route on authentication for my ZF application as well, and was wondering if you would be able to post your method for routing to referer upon authentication.

Best regards,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Peter Schaefer
This post has NOT been accepted by the mailing list yet.
Hello all,

I am running into walls with my authentication plugin, and was hoping that you could take a look and explain to me why it is failing. I have written a front controller plugin that

1) reads protected route paths from a config file,
2) evaluates if requested route is a protected route, and whether user is authenticated
3) if user is authenticated routes to original request,
4) if user is not authenticated, stores initial request object in a session, and
5) routes to the login page,
6) then checks if user is now authenticated and tries to serve the original request from session.

Steps 1-5 work well, and I am able to route to the login page as well as store the original request object in session. When trying to re-route to the original request after user has logged in, the login action gets displayed.

I would greatly appreciate any input / criticism.

Thank you!
Peter

My plugin code:

class PF_Controller_Plugin_Authenticate
        extends Zend_Controller_Plugin_Abstract
{
        /**
         * Default Route Separator
         */
        CONST DEFAULT_SEPARATOR = "/";
       
        /**
         * Session Namespace
         */
        private $_sessionNamespace = 'onAuthenticateGoto';
       
        /**
         * @var array
         */
        private $_protectedRoutes;
       
        /**
         * constructor
         */
        public function __construct($options)
        {
                /** Set options */
                if ($options instanceof Zend_Config) {
            $options = $options->toArray();
        }
        if (!is_array($options)) {
            throw new Exception('Invalid authentication options. Must be array or Zend_Config object');
        }
       
        /** Verify routes exist in options */
        if (! in_array('protectedRoutes', array_keys($options['resources']['frontController'])) ) {
        return; // no protected routes defined
        }
        if (! array_key_exists('routeSeparator', array_keys($options['resources']['frontController'])) ) {
        $options['resources']['frontController']['routeSeparator'] = self::DEFAULT_SEPARATOR;
        }
       
        /** Set Routes */
        $routeSeparator = $options['resources']['frontController']['routeSeparator'];
        foreach ($options['resources']['frontController']['protectedRoutes'] as $key => $route)
        {
        $route = str_replace("/index", "", $route);
        $this->_protectedRoutes['route'][ $key ] = "/{$route}";
       
        //list($controller, $action) = @explode($routeSeparator, $route);
        //$this->_protectedRoutes['controller'][ $key ] = $controller;
        //$this->_protectedRoutes['action'][ $key ] = $action;
        }
        }
       
    /**
     * routeShutdown
     */
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
    $route = $request->getPathInfo();
    $session = new Zend_Session_Namespace('authenticate');
   
                /** Bail out if already logged in, or go to inital request if set */
                if (Zend_Auth::getInstance()->hasIdentity())
                {
                        if ($session->{$this->_sessionNamespace} instanceof Zend_Controller_Request_Http)
                        {
                                $goToRequest = $session->{$this->_sessionNamespace};
                                unset($session->{$this->_sessionNamespace});
                               
                                return $goToRequest;
                        }
                        return;
                }
               
    /** Find Routes that require Authentication */
    if ( ($routeKey = array_search($route, $this->_protectedRoutes['route'])) !== false )
    {
    $session->{$this->_sessionNamespace} = clone $request;
   
    $request->setControllerName('account');
    $request->setActionName('login');
    }
   
    return $request;
    }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Referer

Peter Schaefer
Hello all,

for some reason I am still not able to post on this board. For when my posts get published:

I have written a plugin that reroutes ALMOST exactly how I want it to. Here is the flow:

1) On construct protected routes are read from a config file, and the goTo session namespace, which will be used to store the initial request params, is instantiated
2) on routeShutdown the requested route path is evaluated, it is determined whether authentication has occurred, and whether the path is protected,
3) if request does not require modification, return the request, else re-route to authentication
4) on postDispatch, verify if user is authenticated, this is not the case in the inital re-routed request, hence bail, and the authentication view is dispatched
5) once the user authenticates, on routeShutdown of the plugin , the user is now authenticated, hence we return the request unmodified
6) on postDispatch we note that the user is authenticated, however, there is an unprocessed request stored in the goTo session. We set the reset the response body, since we do not want to serve the authentication view, and set the request parameters to the original request. We then dispatch the original request. The view of the original request is drawn.

Steps 1-6 work well, with one issue I would like to avoid:

Instead of redirecting the user to the original request, which would serve the view with the correct path, I am having to set the reponse body to the originall requested view. Setting up a new route in place of modifying the response, results in a redirect loop. Would anyone be able to help me out with this design problem? Do you have any suggestions how to get around this?

Thank you,
Peter

My Plugin:

class PF_Controller_Plugin_Authenticate
        extends Zend_Controller_Plugin_Abstract
{
        /**
         * Route Separator
         */
        private $_routeSeparator = "/";
       
        /**
         * Route Wildcard
         */
        private $_routeWildcard = "*";
       
        /**
         * Go To Route
         */
        private $_session;
       
        /**
         * Session Namespace
         */
        private $_sessionNamespace = 'PluginAuthenticate';
       
        /**
         * Requested Route
         */
        private $_requestedRoute;
       
        /**
         * @var array
         */
        private $_protectedRoutes;
       
        /**
         * Public Constructor
         */
        public function __construct($options)
        {
                if ($options instanceof Zend_Config) {
                      $options = $options->toArray();
                }
                if (! is_array($options)) {
                     throw new Exception('Invalid authentication options. Must be array or Zend_Config object');
               }
       
               // Verify routes exist in options
               if (! in_array('protectedRoutes', array_keys($options['resources']['frontController'])) ) {
            return;
               }
               if (in_array('routeSeparator', array_keys($options['resources']['frontController'])) ) {
            $this->_routeSeparator = $options['resources']['frontController']['routeSeparator'];
               }
               if (in_array('routeWildcard', array_keys($options['resources']['frontController'])) ) {
            $this->_routeWildcard = $options['resources']['frontController']['routeWildcard'];
               }
       
               // Set Protected Routes
              foreach ($options['resources']['frontController']['protectedRoutes'] as $key => $route)
              {
             $route = str_replace($this->_routeSeparator . "index", "", $route);
             $this->_protectedRoutes['route'][ $key ] = $this->_routeSeparator . $route;
              }
       
          $this->_session = new Zend_Session_Namespace( $this->_sessionNamespace );
        }
       
    /**
     * routeShutdown
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return $request
     * @see Zend_Controller_Plugin_Abstract::routeShutdown
     */
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
    $this->_requestedRoute = $this->_setRoute($request);
   
    /** Find Routes that require Authentication, reroute if found */
    if ( !Zend_Auth::getInstance()->hasIdentity()
    && (array_search($this->_requestedRoute['route'], $this->_protectedRoutes['route']) !== false
    || array_search($this->_requestedRoute['wildcard'], $this->_protectedRoutes['route']) !== false ))
    {
    $this->_session->onAuthenticateGoto = $request->getParams();
   
    $request->setControllerName('account');
    $request->setActionName('login');
    }
   
    return $request;
    }
   
    /**
     * postDispatch
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return $request
     * @see Zend_Controller_Plugin_Abstract::postDispatch()
     */
    public function postDispatch($request)
    {
    /** Bail out if already logged in, and go to request object not set */
                if ( Zend_Auth::getInstance()->hasIdentity()
                        && isset($this->_session->onAuthenticateGoto)
                        && !(empty($this->_session->onAuthenticateGoto)) )
                {
                        $goToRouteParams = $this->_session->onAuthenticateGoto;
                        unset( $this->_session->onAuthenticateGoto );

                        $this->getResponse()->setBody('');
                        $request->setParams($goToRouteParams);
                        $request->setDispatched(false);
                }
               
                return $request;
    }
       
        /**
         * Assemble requested path
         *
         * @param Zend_Controller_Request_Abstract $request
         */
        private function _setRoute($request)
        {
                $options = array(
                        $request->getControllerName(),
                        $request->getActionName()
                );
               
                // direct route to controller/action
                $this->_requestedRoute['route'] = $this->_routeSeparator . implode($this->_routeSeparator, $options);
               
                // target all actions of crontroller
                $this->_requestedRoute['wildcard'] = $this->_routeSeparator .
$request->getControllerName() .  $this->_routeSeparator . $this->_routeWildcard;
                                                                                               
                return $this->_requestedRoute;
        }
}
Loading...