extranet/library/Web/WebAuthAdapter.php

69 lines
2.5 KiB
PHP
Raw Normal View History

2010-11-22 12:50:12 +00:00
<?php
class WebAuthAdapter implements Zend_Auth_Adapter_Interface
{
protected $_username;
protected $_password;
2011-01-06 11:22:26 +00:00
protected $_timeout = 1800;
2011-09-07 12:54:43 +00:00
protected $_checkIp = false;
2010-11-22 12:50:12 +00:00
2011-01-07 17:16:07 +00:00
public function __construct($username, $password, $iponly = false)
2010-11-22 12:50:12 +00:00
{
$this->_username = $username;
$this->_password = $password;
2011-01-07 17:16:07 +00:00
if ($iponly){
$this->_password = 'iponly:'.$_SERVER['REMOTE_ADDR'];
}
2011-09-07 12:54:43 +00:00
$this->_checkIp = $iponly;
2010-11-22 12:50:12 +00:00
}
public function authenticate()
{
2011-01-07 17:16:07 +00:00
$adressIp = $_SERVER['REMOTE_ADDR'];
require_once 'Scores/WsScores.php';
$ws = new WsScores($this->_username, $this->_password);
2011-09-07 12:54:43 +00:00
$InfosLogin = $ws->getInfosLogin($this->_username, $adressIp);
$identity = new stdClass();
$identity->username = $this->_username;
if ($this->_checkIp){
$identity->password = $this->_password;
} else {
$identity->password = md5($this->_username.'|'.$this->_password);
}
$identity->email = $InfosLogin->result->email;
$identity->profil = $InfosLogin->result->profil;
$identity->pref = $InfosLogin->result->pref;
$identity->droits = $InfosLogin->result->droits;
$identity->droitsClients = $InfosLogin->result->droitsClients;
$identity->nom = $InfosLogin->result->nom;
$identity->prenom = $InfosLogin->result->prenom;
$identity->tel = $InfosLogin->result->tel;
$identity->fax = $InfosLogin->result->fax;
$identity->mobile = $InfosLogin->result->mobile;
$identity->id = $InfosLogin->result->id;
$identity->idClient = $InfosLogin->result->idClient;
$identity->reference = $InfosLogin->result->reference;
$identity->nbReponses = $InfosLogin->result->nbReponses;
$identity->typeScore = $InfosLogin->result->typeScore;
$identity->timeout = (!empty($InfosLogin->result->timeout)) ?
$InfosLogin->result->timeout : $this->_timeout;
$identity->ip = $adressIp;
$identity->modeEdition = false;
2011-01-07 17:16:07 +00:00
$logger = Zend_Registry::get('firebug');
$logger->log($identity, Zend_Log::DEBUG);
if ( (is_string($InfosLogin) && !empty($InfosLogin)) || $InfosLogin->error->errnum!=0){
if (is_string($InfosLogin)){
$message = $InfosLogin;
} else {
$message = 'Erreur lors de la connexion';
}
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity, array($message));
2011-01-07 17:16:07 +00:00
} elseif ($this->_username == $InfosLogin->result->login) {
2011-01-05 15:14:23 +00:00
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
2010-11-22 12:50:12 +00:00
} else {
2011-01-05 15:14:23 +00:00
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED, $identity);
2010-11-22 12:50:12 +00:00
}
}
2011-01-07 17:16:07 +00:00
2010-11-22 12:50:12 +00:00
}