开发者

Using Zend_Auth in Pimcore

开发者 https://www.devze.com 2023-02-27 06:41 出处:网络
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 pim

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


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号