58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
|
{
|
|
protected $_username;
|
|
protected $_password;
|
|
protected $_hash;
|
|
protected $_timeout = 1800;
|
|
protected $checkWs = true;
|
|
|
|
public function __construct($username, $password, $checkWs = true)
|
|
{
|
|
$this->_username = $username;
|
|
$this->_password = $password;
|
|
$this->_hash = md5($username.'|'.$password);
|
|
$this->checkWs = $checkWs;
|
|
}
|
|
|
|
public function authenticate()
|
|
{
|
|
$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);
|
|
}
|
|
}
|
|
}
|
|
} |