如何从CakePHP中的多个登录位置获取loginRedirect? [英] How do I get the loginRedirect from multiple login locations in CakePHP?

查看:121
本文介绍了如何从CakePHP中的多个登录位置获取loginRedirect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CakePHP应用程式中取得验证功能,并尝试使用Cookie。

I'm trying to get authentication working to my liking in a CakePHP app and running into a snag.

我想让用户从主页或专用登录页面登录。我使用Auth组件来管理登录,现在登录本身工作。我将主页上的表单提交到/ Users / Login,它会将它们登录并创建会话。问题是它然后重定向用户回到主页。我宁愿他们重定向到loginRedirect中指定的位置。

I want to let the user login from either the home page or from a dedicated login page. I'm using the Auth component to manage login and right now the login itself works. I am submitting the form on the home page to /Users/Login and it does log them in and create session. The problem is it then redirects the user back to the home page. I'd rather they redirect to the location specified in loginRedirect.

如果我直接从/ users / login登录,它会转发到loginRedirect。我认为这个问题与将表单从一个页面发布到另一个页面而不是自己,auth自动认为你想回到上一页。

If i login from /users/login directly it does forward to loginRedirect. I think the problem has something to do with posting the form from one page to another page instead of to itself, auth automatically thinks you want to go back to the previous page.

AppController中的任何想法?

Any thoughts?

推荐答案



in the AppController

public function beforeFilter( )
{
    $this->Auth->autoRedirect	=	false;
}

在UsersController

in UsersController

public function login( )
{
    if( $this->Auth->user( ) )
    {
    	$this->redirect( array(
    		'controller'	=>	'users'	,
    		'action'	=>	'index'	,
    	));
    }
}

此外,如果您还没有将表单插入元素,以便您可以确保登录表单在两个登录视图之间是相同的。

Also, if you haven't already you should move the form into an element, so that you can make absolutely certain that the login form is identical between the 2 login views.

这篇关于如何从CakePHP中的多个登录位置获取loginRedirect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆