webservice/library/Web/WebAuthAdapter.php
2011-02-15 16:49:06 +00:00

54 lines
2.2 KiB
PHP

<?php
require_once 'framework/fwk.php';
require_once 'framework/common/mysql.php';
class WebAuthAdapter implements Zend_Auth_Adapter_Interface
{
protected $_username;
protected $_password;
protected $_hash;
public function __construct($username,$password)
{
$this->_username = $username;
$this->_password = $password;
$this->_hash = md5($username.'|'.$password);
}
public function authenticate()
{
/*
$identity = new stdClass();
$identity->username = $this->_username;
$identity->hash = $this->_hash;
$identity->idClient = 1;
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
*/
$iDbCrm = new WDB('sdv1');
$rep = $iDbCrm->select(
'utilisateurs u, clients c',
'u.login, u.id, u.email, u.password, u.idClient, u.typeCompte, u.actif, u.filtre_ip, u.civilite, u.nom, u.prenom, u.tel, u.fax, u.mobile, u.profil, u.raisonSociale, u.siret, u.adrNum, u.adrIndRep, u.adrTypeVoie, u.adrLibVoie, u.adrCp, u.adrVille, u.adrComp, u.tel, u.fax, u.mobile, u.pref, u.profil, u.dateInscription, u.dateValidation, u.nombreConnexions, u.dateDerniereConnexion, u.droits, u.referenceParDefaut, u.nbReponses, u.formatMail, u.dateDebutCompte, u.dateFinCompte, u.maxFicheId, c.droits AS droitsClients, c.timeout',
"u.login='$this->_username' AND u.idClient=c.id AND u.actif=1 AND u.deleted=0 AND u.accesWS=1 AND c.actif='Oui'",
false, MYSQL_ASSOC);
$tabRep = $rep[0];
$identity = new stdClass();
$identity->username = $this->_username;
$identity->hash = $this->_hash;
$identity->idClient = $tabRep['idClient'];
if (count($rep)==0){
//debugLog('W',"CheckAuth $login/$password inexistant ou inactif (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $identity);
} else {
if ( $tabRep['password']==$this->_password ){
//debugLog('W',"CheckAuth $login/$password OK", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
} else {
//debugLog('W',"CheckAuth $login/$password incorrect (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity);
}
}
}
}