Remove Zend_Db

This commit is contained in:
Michael RICOIS 2017-02-06 16:10:37 +01:00
parent a468c819db
commit c7bb17a356

View File

@ -14,7 +14,19 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
protected $clients = array();
/**
*
* PDO Connection with Doctrine
* @var \Doctrine\DBAL\Connection
*/
protected $conn;
/**
* Logger
* @var \Monolog\Logger
*/
protected $logger;
/**
* Auth DB
* @param string $username
* @param string $password
* @param boolean $checkWs
@ -25,6 +37,12 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
$this->_password = $password;
$this->_hash = md5($username.'|'.$password);
$this->checkWs = $checkWs;
$this->conn = Zend_Registry::get('doctrine');
if (Zend_Registry::isRegistered('logger')) {
$this->logger = Zend_Registry::get('logger');
}
}
/**
@ -33,7 +51,7 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
*/
public function limitClient($id = null)
{
if (is_array($id) && count($id)>0) {
if (is_array($id) && count($id) > 0) {
$this->clients = $id;
}
}
@ -44,7 +62,7 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
*/
public function setTimeout($seconds = null)
{
if ($seconds===null) {
if ($seconds === null) {
return;
}
@ -57,23 +75,28 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
*/
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');
try {
$qb = $this->conn->createQueryBuilder();
$qb->select(array('u.idClient', 'u.id', 'u.login', 'u.password', 'c.timeout'))
->from('sdv1.utilisateurs', 'u')
->join('u', 'sdv1.clients', 'c', 'u.idClient = c.id')
->where("u.login=:login")->setParameter('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).')');
$qb->where('u.idClient IN('.join(',', $this->clients).')');
}
if ($this->checkWs) {
$sql->where('u.accesWS=?', 1);
$qb->where('u.accesWS=1');
}
$stmt = $qb->execute();
} catch (\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
$result = $userM->fetchRow($sql);
@ -82,8 +105,9 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
$identity->username = $this->_username;
$identity->hash = $this->_hash;
if (null === $result) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $identity, array("Identifiant ou mot de passe invalid"));
if ($stmt->rowCount() == 0) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $identity,
array("Identifiant ou mot de passe invalid"));
} else {
if ($this->_password == $result->password
|| $this->_password == md5($result->login.'|'.$result->password)) {
@ -93,9 +117,11 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
*/
if (!empty($result->dateDebutCompte) && $result->dateDebutCompte!='0000-00-00') {
$today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$dateDebutCompte = mktime(0, 0, 0, substr($result->dateDebutCompte, 5, 2), substr($result->dateDebutCompte, 8, 2), substr($result->dateDebutCompte, 0, 4));
$dateDebutCompte = mktime(0, 0, 0, substr($result->dateDebutCompte, 5, 2),
substr($result->dateDebutCompte, 8, 2), substr($result->dateDebutCompte, 0, 4));
if ($today < $dateDebutCompte) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity, array("Date de validité dépassé"));
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity,
array("Date de validité dépassé"));
}
}
@ -104,9 +130,11 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
*/
if (!empty($result->dateFinCompte) && $result->dateFinCompte!='0000-00-00') {
$today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$dateFinCompte = mktime(0, 0, 0, substr($result->dateFinCompte, 5, 2), substr($result->dateFinCompte, 8, 2), substr($result->dateFinCompte, 0, 4));
$dateFinCompte = mktime(0, 0, 0, substr($result->dateFinCompte, 5, 2),
substr($result->dateFinCompte, 8, 2), substr($result->dateFinCompte, 0, 4));
if ($today > $dateFinCompte) {
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity, array("Date de validité dépassé"));
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity,
array("Date de validité dépassé"));
}
}
@ -117,7 +145,8 @@ class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
$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, array("Identification impossible"));
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity,
array("Identification impossible"));
}
}
}