我是Pimcore的新手,我正在尝试将Zend Auth与pimcore对象一起使用。我认为这是一种明智的方法,在我看来或多或少是合乎逻辑的。我已经在pimcore中完成了对象的初始设置。现在,我正在尝试解决如何将其连接到zend auth,例如,当我扩展zend auth并拥有自己的登录函数时,如何检查登录在我的对象中是否有效?
有没有人有我可以用的指南呢?否则,如果有人能给我指出正确的方向,那就太好了。
杰森
发布于 2011-07-07 00:02:44
你可以遵循这个指南:http://www.pimcore.org/forum/discussion/419/zend_auth_adapter-for-pimcore-objects,它对我来说工作得很好。
更新:上面的链接已经被删除,所以在这里提供完整的答案:
首先,您需要将ObjectAdapter.php放在website/lib/Website/Auth/ObjectAdapter.php中。
然后,这是您登录用户的方式(根据您的喜好使用,例如,在您的控制器init函数中):
$authAdapter = new Website_Auth_ObjectAdapter('Object_Users', 'o_key', 'password', '/users/');
// The parameters are 1. object you keep your users in, 2. the field that contains their username (I use o_key which is the name of the object itself, to keep unique usernames without fuzz), and 3. the password field in the user object.
// Setup auth adapter
$authAdapter->setIdentity($username)->setCredential($password);
$auth = Zend_Auth::getInstance();
// Authenticate
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
// Login successful
} else {
// Login failed
}要检查登录会话,请使用:
$this->auth = Zend_Auth::getInstance();
if ($this->auth->hasIdentity()) {
// We have a login session (user is logged in)
$userObject = $this->auth->getIdentity();
} 要终止会话,请执行以下操作:
Zend_Auth::getInstance()->clearIdentity();https://stackoverflow.com/questions/5703087
复制相似问题