Well, yeah -- if I understand correctly, that's what I've done.
Model_AuthAdapter extends Zend_Auth_Adapter_DbTable
{
const FAILURE_ACCOUNT_DISABLED = 'Account disabled.';
function authenticate() {
$this->_authenticateResultInfo['identity'] = $this->_identity;
// stolen from parent
if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) {
$this->_credentialTreatment = '?';
}
$credentialExpression = new Zend_Db_Expr(
'(CASE WHEN ' .
$this->_zendDb->quoteInto(
$this->_zendDb->quoteIdentifier($this->_credentialColumn, true)
. ' = ' . $this->_credentialTreatment, $this->_credential
)
. ' THEN 1 ELSE 0 END) AS '
. $this->_zendDb->quoteIdentifier('zend_auth_credential_match')
);
// end stolen part
if ($this->_identityColumn == 'username') {
$identityColumn = 'users.username';
} elseif ($this->_identityColumn == 'email') {
$identityColumn = 'people.email';
} else {
throw new Exception('invalid identity column: '.$this->_identityColumn);
}
$select = $this->_zendDb->select();
$select
->from($this->_tableName, array('username','group_id','active','last_login', $credentialExpression))
->join('groups','users.group_id =
groups.id',array('group'=>'
groups.name'))
->join('people','users.person_id =
people.id',array('id','lastname','firstname','email'))
->join('person_types','people.person_type_id =
person_types.id',array('person_type'=>'flavor'))
->where("$identityColumn = ? ",$this->_identity) ;
$this->_zendDb->setFetchMode(Zend_Db::FETCH_OBJ);
$results = $this->_zendDb->fetchAll($select);
// borrowed from parent
if ( ($authResult = $this->_authenticateValidateResultset($results)) instanceof Zend_Auth_Result) {
return $authResult;
}
$user = array_shift($results);
$authResult = $this->_authenticateValidateResult((array)$user);
// if everything is good so far, make sure account is active
if ($authResult->isValid()) {
if (! $user->active) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED,
$this->_identity,array(self::FAILURE_ACCOUNT_DISABLED));
}
}
$this->_zendDb->update('users', array('last_login' => time()), $this->_zendDb->quoteInto( 'person_id = ?', $user->id ) );
return $authResult;
}
}
Thank you Ralph.