1

我是 Pimcore 的新手,我正在尝试将 Zend Auth 与 pimcore 对象一起使用。我认为这是一种明智的方法,对我来说似乎或多或少是合乎逻辑的。我已经在 pimcore 本身内完成了对象的初始设置。现在我正在尝试解决如何将它连接到 zend auth,例如,当我扩展 zend auth 并拥有自己的登录功能时,如何检查登录在我的对象中是否有效?

有人有我可以使用的指南吗?否则,如果有人能指出我正确的方向,那就太好了

杰森

4

1 回答 1

3

您可以遵循本指南:http ://www.pimcore.org/forum/discussion/419/zend_auth_adapter-for-pimcore-objects ,它对我很有效。

更新:上面的链接已被删除,所以在这里列出完整的答案:

首先,您需要将ObjectAdapter.php放在 website/lib/Website/Auth/ObjectAdapter.php 中。

然后,这就是您登录用户的方式(根据您的喜好使用,例如在您的控制器初始化函数中):

$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();
于 2011-07-06T16:02:43.960 回答