_username = $username; $this->_password = $password; $this->_hash = md5($username.'|'.$password); $this->checkWs = $checkWs; } /** * Limit access to only client IDs * @param array $id */ public function limitClient($id = null) { if (is_array($id) && count($id)>0) { $this->clients = $id; } } /** * Override the timeout * @param integer $seconds */ public function setTimeout($seconds = null) { if ($seconds===null) return; $this->_timeout = $seconds; } /** * (non-PHPdoc) * @see Zend_Auth_Adapter_Interface::authenticate() */ public function authenticate() { $userM = new Application_Model_Sdv1Utilisateurs(); $sql = $userM->select() ->setIntegrityCheck(false) ->from(array('u'=>'sdv1.utilisateurs'), array('u.idClient', 'u.id', 'u.login', 'u.password')) ->join(array('c'=>'sdv1.clients'), 'u.idClient = c.id', array('c.timeout')) ->where('u.login=?', $this->_username) ->where('u.actif=?', 1) ->where('u.deleted=?', 0) ->where('c.actif=?','Oui'); if ( count($this->clients) > 0 ) { $sql->where('u.idClient IN('.join(',',$this->clients).')'); } if ($this->checkWs) { $sql->where('u.accesWS=?',1); } $result = $userM->fetchRow($sql); $identity = new stdClass(); $identity->username = $this->_username; $identity->hash = $this->_hash; if ( null === $result ) { return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $identity); } else { if ( $this->_password == $result->password || $this->_password == md5($result->login.'|'.$result->password) ) { $identity->id = $result->id; $identity->idClient = $result->idClient; $timeout = (!empty($result->timeout)) ? $result->timeout : $this->_timeout; $identity->timeout = $timeout; $identity->time = time() + $timeout; return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity); } else { return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity); } } } }