我的网站上有 2 个身份验证区域。 - 域/管理员(管理区域) - 域/客户端(客户区)
管理员具有不同的模型,客户端具有不同的模型。
我正在使用 $this->身份验证();我使用以下代码来识别用户是否获得授权。
public function isAuthorized($user) {
// Client ACL
if ($this->params['controller'] == 'clients'):
if (isset($user) && !empty($user['business_type'])) {
return true;
} else {
return false;
}
endif;
}
这工作正常。问题是,当我登录到管理区域并转到客户区域URL时,它显示为我已登录。我想为管理区和客户区进行 2 个不同的会话。
如何识别用户是否实际登录到管理区域或客户区域。我想开发一种机制,其中管理员和客户端可以同时从同一浏览器登录。
我也在管理区域使用管理员前缀,这就是为什么管理区域的 isAthorized 代码存储在 AppController 中的原因.php
你必须使用 AuthComponent::$sessionKeyhttp://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$sessionKey
由于使用的是管理员前缀,因此可以在 AppController.php 中为管理区域设置$sessionKey。
例:
AuthComponent::$sessionKey = 'Auth.Admin';
在客户端的控制器中,您可以为客户端创建另一个会话密钥。
AuthComponent::$sessionKey = 'Auth.Client';
这将解决问题。