|
|
Re: Using Zend_Auth to retrieve a user's role to use in Zend_Acl: msg#00017
php.zend.framework.auth
|
Subject: |
Re: Using Zend_Auth to retrieve a user's role to use in Zend_Acl |
On 03/10/2007, David Mintz <david-dMffkYQFJ3MKxoK4Ny/0iQ@xxxxxxxxxxxxxxxx> wrote:
That probably isn't necessary. Here is my authenticate() from the helper I wrote. Suppose "role" is a column from your user table. If you do something like this, you will have $user->role available to you. (This is substantially stolen from the docs). HTH.
function authenticate($username,$password) { $db = Zend_Registry::get('db'); $view = $this->getActionController()->view; // I get some config stuff from an ini file and then...
$authAdapter = new Zend_Auth_Adapter_DbTable($db, $config->tablename, $config->usercol, 'password'); $result = $authAdapter->setIdentity($username) ->setCredential($password)
->authenticate(); $this->result = $result;
if ($result->isValid()) { $auth = Zend_Auth::getInstance(); $user = $authAdapter->getResultRowObject(null,'password');
$auth->getStorage()->write($user); $view->user = $user; // so we can easily say "welcome Joe User" Zend_Session::regenerateId(); return true;
} else { // authentication failed. let the caller deal with it by calling our getResult(); return false; } } David, that did help a lot, and I think this will help me solve this, so thanks. I can now add a method to my adapter that will return the user's data in an array, and then when logging in, do an $auth->getStorage()->write($role); . This will probably solve it, but I was wondering whether there was a more elegant way,
i.e. to automatically make AuthAdapter store this when I call $auth->authenticate($authAdapter);
Again, thanks a lot, I was really getting desperate!
On 10/3/07, Vincent <imnotb-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> wrote:
After having read some more, I am now thinking of subclassing Zend_Auth_Result to make it include the user's role. I'm not quite sure whether this would be the best way to go about though, so I'd like to ask for some feedback on whether you guys think this to be a good idea.
-- David Mintz http://davidmintz.org/
The subtle source is clear and bright The tributary streams flow through the darkness
-- Vincent
|
|