Autoloading : Auth Adapter
This commit is contained in:
parent
76945f3b39
commit
e85d54a986
@ -354,7 +354,7 @@ class UserController extends Zend_Controller_Action
|
||||
$pass = $form->getValue('pass');
|
||||
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$authAdapter = new Scores_AuthAdapter($login, md5($login.'|'.$pass));
|
||||
$authAdapter = new Scores_Auth_Adapter_Ws($login, md5($login.'|'.$pass));
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
|
||||
//Auth is valid
|
||||
|
@ -13,7 +13,7 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
if ($request->getControllerName()=='user' && $request->getActionName()=='login') {
|
||||
$checkAuth = false;
|
||||
}
|
||||
|
||||
|
||||
if ($request->getControllerName()=='user' && $request->getActionName()=='motpasse') {
|
||||
$checkAuth = false;
|
||||
}
|
||||
@ -42,7 +42,7 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
//On vérifie le tout lors d'une connexion par url
|
||||
if ( !empty($login) && !empty($hach) ) {
|
||||
|
||||
$authAdapter = new Scores_AuthAdapter($login, $hach, $iponly);
|
||||
$authAdapter = new Scores_Auth_Adapter_Ws($login, $hach, $iponly);
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
|
||||
if ( $result->isValid() ) {
|
||||
|
102
library/Scores/Auth/Adapter/Db.php
Normal file
102
library/Scores/Auth/Adapter/Db.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
class Scores_Auth_Adapter_Db implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
protected $_username;
|
||||
|
||||
protected $_password;
|
||||
|
||||
protected $_hash;
|
||||
|
||||
protected $_timeout = 3600;
|
||||
|
||||
protected $checkWs = false;
|
||||
|
||||
protected $clients = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param boolean $checkWs
|
||||
*/
|
||||
public function __construct($username, $password, $checkWs = false)
|
||||
{
|
||||
$this->_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'=>'utilisateurs'), array('u.idClient', 'u.id', '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 ( 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,28 @@
|
||||
<?php
|
||||
class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
||||
class Scores_Auth_Adapter_Ws implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var unknown
|
||||
*/
|
||||
protected $_username;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var unknown
|
||||
*/
|
||||
protected $_password;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var unknown
|
||||
*/
|
||||
protected $_timeout = 1800;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var unknown
|
||||
*/
|
||||
protected $_checkIp = false;
|
||||
|
||||
public function __construct($username, $password, $iponly = false)
|
||||
@ -16,6 +35,10 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
||||
$this->_checkIp = $iponly;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see Zend_Auth_Adapter_Interface::authenticate()
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$adressIp = $_SERVER['REMOTE_ADDR'];
|
||||
@ -44,7 +67,7 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
||||
$identity->dateValidation = $InfosLogin->result->dateValidation;
|
||||
$identity->nombreConnexions = $InfosLogin->result->nombreConnexions;
|
||||
$identity->dateDerniereConnexion = $InfosLogin->result->dateDerniereConnexion;
|
||||
$identity->dateDebutCompte = $InfosLogin->result->dateDebutCompte;
|
||||
$identity->dateDebutCompte = $InfosLogin->result->dateDebutCompte;
|
||||
$identity->dateFinCompte = $InfosLogin->result->dateFinCompte;
|
||||
$identity->acceptationCGU = $InfosLogin->result->acceptationCGU;
|
||||
$identity->ip = $adressIp;
|
||||
@ -93,9 +116,13 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
||||
}
|
||||
|
||||
/**
|
||||
* Controle si une adresse IP est dans une liste des IP communiquées sous la forme 192.168.3.5-192.68.3.10;192.168.3.*;192.168.3.10
|
||||
* @param string $strPlageIP La plage d'adresses IP
|
||||
* @param string $adresseIP L'adresse IP à tester
|
||||
* Controle si une adresse IP est dans une liste des IP communiquées sous la forme
|
||||
* 192.168.3.5-192.68.3.10;192.168.3.*;192.168.3.10
|
||||
* @param string $strPlageIP
|
||||
* La plage d'adresses IP
|
||||
* @param string $adresseIP
|
||||
* L'adresse IP à tester
|
||||
* @return boolean
|
||||
*/
|
||||
protected function checkPlagesIp($strPlageIP, $adresseIP)
|
||||
{
|
||||
@ -143,7 +170,8 @@ class Scores_AuthAdapter implements Zend_Auth_Adapter_Interface
|
||||
* @param string $ip Adresse IP
|
||||
* @return integer
|
||||
*/
|
||||
protected function getIpNumber($ip) {
|
||||
protected function getIpNumber($ip)
|
||||
{
|
||||
$tab=explode('.', $ip);
|
||||
return (($tab[0]*256*256*256) + ($tab[1]*256*256) + ($tab[2]*256) + ($tab[3]));
|
||||
}
|
Loading…
Reference in New Issue
Block a user