在 Pimcore 中使用 Zend_Auth

发布于 2024-11-01 21:38:26 字数 244 浏览 0 评论 0原文

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

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

杰森

Im new to Pimcore and I'm trying to use Zend Auth with pimcore objects. I assume this is a wise approach and it seems more or less logical to me. I've done the initial setup of the object within pimcore itself. Now I'm trying to work out how to connect it to zend auth, that is, for example when I extend zend auth and have my own login function, how do i check if the login is valid in my object?

Does someone have a guide that I could use on this perhaps? otherwise if someone could point me in the right direction that would be great

Jason

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑饮青盏花 2024-11-08 21:38:26

您可以按照以下指南进行操作: 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();

You can follow this guide: http://www.pimcore.org/forum/discussion/419/zend_auth_adapter-for-pimcore-objects , it worked well for me.

UPDATE: The link above has been taken away, so laying out the full answer here:

First, you need to put ObjectAdapter.php in website/lib/Website/Auth/ObjectAdapter.php .

Then, this is how you login your user (use as you prefer, for example in your controller init function):

$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
}

To check for a login-session, use:

$this->auth = Zend_Auth::getInstance();
if ($this->auth->hasIdentity()) { 
    // We have a login session (user is logged in)
    $userObject = $this->auth->getIdentity();
}   

To kill a session:

Zend_Auth::getInstance()->clearIdentity();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文