开发者

Pass query string when user is redirected to login

I have a CakePHP website at the following url: http://driz.co.uk/

When a user (me) tries to access the portfolio admin at http://driz.co.uk/admin/portfolio/ they are automatically taken to the admin login at http://driz.co.uk/admin/login because the admin methods all require authentication.

What I want to do is pass the query string of the last page as well so when that redirect happens it will say this in the URL: http://driz.co.uk/admin/login?continue=/admin/portfolio/

How would I do this?

I've tried:

        $this->Auth->loginAction = array(
            'admin' => true,
            'prefix'=> 'admin',
            'controller' => 'users',
            'action' => 'login',
            '?' => array('continue' => $this->refer开发者_运维百科er())
        );

But that just causes a redirect loop (not sure why it's even trying to do a redirect :/

Note: I know CakePHP automatically redirects the user after successful login BUT I want to add the query string as I'm using it for extra jazz in the app.

Thanks


Cake automatically (if I recall) returns you to page you attempted to access after logging in, unless you mess with $this->Auth->redirectLogin.

You might have luck with this in a before filter:

$this->Auth->loginAction = array('controller'=>'users',
                                 'action'=>'login', 
                                 '?' => array('continue'=>'/' .
                                    strtolower($this->name) . '/' .
                                    $this->action), 'admin'=>false);

(dodgy line breaks added by me).

This will produce:

site.com/admin/login?continue=%2Fcontroller%2Faction which is equivalent, more or less, to what you require.

You may or may not need/want admin=>false.

essentially this appends the current controller name and action to the loginAction redirect. Probably a bit of a dodgy hack I do not know how to prevent cake encoding the slashes


In login() function, you can get the last page at $this->Session->read('Auth.redirect'); So no need to add it in the url.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜