[英]How do I allow non-authenticated users to access content in CakePHP?
我在cakephp 2.x中有一個站點,我希望訪客用戶(未登錄)可以看到相同的頁面:
用戶/登錄
用戶/忘記密碼
用戶/重置密碼
我的AuthComponent無法訪問我的頁面。 我可以訪問用戶/登錄名,但不能訪問forgot_password和reset_password,如果我嘗試始終將其重定向到登錄頁面。
這是我的帶有AuthComponent的AppController:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array('controller'=>'users','action'=>'login', 'admin'=>false),
'logoutRedirect' => array('controller'=>'users','action'=>'login'),
'loginRedirect' => array('controller'=>'projects', 'action'=>'index'),
'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
'autoRedirect' => false,
'authorize' => array(
'Controller',
'Actions' => array(
'actionPath' => 'controllers'
)
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
在這種情況下,我無法訪問forgot_password和reset_password。
但是,如果我將其更改為:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => null,
'logoutRedirect' => array('controller'=>'users','action'=>'login'),
'loginRedirect' => array('controller'=>'projects', 'action'=>'index'),
'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
'autoRedirect' => false,
'authorize' => array(
'Controller',
'Actions' => array(
'actionPath' => 'controllers'
)
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
在這種情況下,我將null
設置為loginAction
,我可以訪問forgot_password和reset_password,但是頁面為空白,沒有錯誤,正文為空。 這些頁面只是html,沒有這樣的查詢:
控制器動作
public function forgot_password(){
}
視圖
<div>
<p>RESTORE PASSWORD</p>
</div>
有人可以幫我嗎? 謝謝
在您的beforeFilter()
回調中,添加$this->Auth->allow('forgot_password');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.