2010-09-13 09:00:36 +00:00
|
|
|
<?php
|
2012-05-20 13:11:13 +00:00
|
|
|
class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
2010-09-13 09:00:36 +00:00
|
|
|
{
|
|
|
|
protected $_username;
|
|
|
|
protected $_password;
|
2010-12-08 14:08:09 +00:00
|
|
|
protected $_hash;
|
2011-08-30 12:08:07 +00:00
|
|
|
protected $_timeout = 1800;
|
2012-03-06 12:42:31 +00:00
|
|
|
protected $checkWs = true;
|
2010-09-13 09:00:36 +00:00
|
|
|
|
2012-02-23 10:08:50 +00:00
|
|
|
public function __construct($username, $password, $checkWs = true)
|
2010-09-13 09:00:36 +00:00
|
|
|
{
|
|
|
|
$this->_username = $username;
|
|
|
|
$this->_password = $password;
|
2010-12-08 14:08:09 +00:00
|
|
|
$this->_hash = md5($username.'|'.$password);
|
2012-03-06 12:42:31 +00:00
|
|
|
$this->checkWs = $checkWs;
|
2010-09-13 09:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function authenticate()
|
|
|
|
{
|
2013-02-21 17:03:56 +00:00
|
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
|
|
|
|
|
|
$sql = $userM->select()
|
|
|
|
->setIntegrityCheck(false)
|
|
|
|
->from(array('u'=>'utilisateurs'), array('u.idClient', 'u.login', 'u.password'))
|
|
|
|
->join(array('c'=>'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 ($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->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);
|
|
|
|
}
|
|
|
|
}
|
2010-09-13 09:00:36 +00:00
|
|
|
}
|
|
|
|
}
|