我认为,这样做的唯一途径是创建一个客座用户。 这是因为,Austh构成部分像你所解释的那样,先检查用户的存在,然后才到isAuthorized(>
。
你可以直接向本届会议写信。 这将告诉奥特部分,有人被gged住,因此,请打电话isAuthorized(
)。
<><>AppController>
public function beforeFilter() {
// if no one is logged in, log in a guest
if (!$this->Auth->user()) {
$this->Session->write(AuthComponent::$sessionKey, array(
User => array(
id => 0
)
));
}
}
public function isAuthorized($user) {
$authorized = false;
if ($this->Auth->user( id ) == 0) {
// public guest user access
}
// other logic
return $authorized;
}
这样做的一个可能更好的途径是使用习惯认证标语,该标语基本上指Cake使用这一类别来帮助认证。 这种做法将逻辑分成一个单独的类别,使测试更加容易,甚至变得不可行。
app/Controller/Component/Auth/GuestAuthenticate.php
App::uses( BaseAuthenticate , Controller/Component/Auth );
class GuestAuthenticate extends BaseAuthenticate {
public function authenticate(CakeRequest $request, CakeResponse $response) {
// no real authentication logic, just return a guest user
return array( User => array( id => 0));
}
}
<><>AppController>
public $components = array(
Auth => array(
authenticate => array(
Form ,
Guest // tell Cake to try Form authentication then Guest authentication
)
)
);
public function beforeFilter() {
if (!$this->Auth->user()) {
// no user? log in a guest (this will fail form authentication
// then try guest authentication)
$this->Auth->login();
}
}
public function isAuthorized($user) {
$authorized = false;
if ($this->Auth->user( id ) == 0) {
// public guest user access
}
// other logic
return $authorized;
}
http://book.cakephp。