cakephp auth 组件允许重定向问题
当我使用 $this->Auth->allow('index','view'); 时,我遇到了 Auth 组件问题;
当我使用 $this->Auth->allow('*')
时,我收到 /users/login 导致了太多重定向,它工作正常。我使用 cakephp 1.3.12 这里是 app_controller.php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter(){
$this->Auth->allow('index','view');
}
}
我更改了 app_controller.php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter(){
$this->Auth->allow(array('index','view','display'));
}
}
users_controller.php
class UsersController extends AppController {
var $name = 'Users';
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow(array('login','logout'));
}
function login() {
if ($this->Session->read('Auth.User')) {
$this->redirect('/', null, false);
}
}
paths.php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
有什么建议吗? 谢谢
I am having problem with Auth component when I use $this->Auth->allow('index','view');
I am getting /users/login has resulted in too many redirects when I use $this->Auth->allow('*')
it works fine. I am using cakephp 1.3.12 here is app_controller.php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter(){
$this->Auth->allow('index','view');
}
}
I changed the app_controller.php
class AppController extends Controller {
var $components = array('Auth','Session');
function beforeFilter(){
$this->Auth->allow(array('index','view','display'));
}
}
users_controller.php
class UsersController extends AppController {
var $name = 'Users';
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow(array('login','logout'));
}
function login() {
if ($this->Session->read('Auth.User')) {
$this->redirect('/', null, false);
}
}
routes.php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
any suggestions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不知道,但您可能想检查是否有任何请求操作。
“如果您在布局或元素中使用 requestAction,则应该允许这些操作,以便能够正确打开登录页面。”
http://book.cakephp.org/1.3/en/view/1257/allow
这让我困惑了很长时间。
假设您在模板中的某处渲染了一个元素:
在views/elements/comments.ctp 中,您有一些请求操作的内容,例如
在您的CommentsController 中,您必须执行以下操作:
请注意,您正在从元素中的注释控制器请求索引操作。这就是为什么您必须允许该特定控制器的“索引”。
我还没有在任何地方看到这个问题得到妥善解决。希望这就是导致您错误的原因。
Don't know but you might want to check if you have any request actions.
"If you are using requestAction in your layout or elements you should allow those actions in order to be able to open login page properly."
http://book.cakephp.org/1.3/en/view/1257/allow
This had me stumped for the longest time.
Let's say you render an element somewhere in your template:
And in views/elements/comments.ctp you have something that requests an action like
In your CommentsController your have to:
Notice you are requesting an index action from your comments controller in your element. That's why you have to allow 'index' for that specific controller.
I haven't seen this problem properly addressed anywhere. Hope that's what is causing your error.
它是一个数组 =)
由于 /user/login 操作无法访问,因此您会收到
too much redirects
消息。因此,服务器尝试显示登录页面,但它不能,因为常规的未连接用户无法访问 /user/login。当用户无法访问某个页面时,服务器会将他重定向到登录页面......所以你看,这是一个无限循环。/user/login 操作应该授权给每个人。您的
Users
控制器应如下所示:如果这不是问题,也许您正在重定向 paths.php 中的页面
希望这会有所帮助
its an array =)
your getting the
too many redirects
message becasuse the /user/login action is not accessible. So the server tries to display the login page, but it can't, because regular non-connected users dont have acces to /user/login. And when a user doesn't have access to a page, the server will redirect him to the login page... so you see, its an infinite loop.The /user/login action should be authorized to everyone. Your
Users
controller should look like this:if this doesn't the problem, maybe you're redirecting the page in the routes.php
Hope this helps
你做错了。应用程序如何知道你正在尝试控制哪个控制器操作。从你的控制器执行它。
从应用程序中删除它
在您的应用程序控制器中尝试进行所需的更改,
从您的用户控制器执行此操作
并且在您的登录中不要执行任何操作,所有重定向都将由应用程序控制器执行。
如果您对此有任何疑问,请给我发邮件
you are doing it wrong.How can app can get to know that which of your controller action you are trying to controller.Do it from your controller.
remove this from app
try this in your app controller with needed change
do this from your user controller
And in your login dont do anything all of your redirect and all will be doing by app controller.
If you have any doubt regarding this mail me