extranet/library/Web/WebAuthAdapter.php

61 lines
2.1 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;
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'];
}
$this->_checkIp = false;
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);
$InfosLogin = $ws->getInfosLogin($this->_username, $adressIp);
$identity = new stdClass;
2011-01-05 15:14:23 +00:00
$identity->username = $this->_username;
2011-04-01 12:14:40 +00:00
$identity->password = $this->_password; // @todo : Hash ?
2011-01-07 17:16:07 +00:00
$identity->email = $InfosLogin->result->email;
$identity->profil = $InfosLogin->result->profil;
$identity->pref = $InfosLogin->result->pref;
$identity->droits = $InfosLogin->result->droits;
2011-04-01 12:14:40 +00:00
$identity->droitsClients = $InfosLogin->result->droitsClients;
2011-01-07 17:16:07 +00:00
$identity->nom = $InfosLogin->result->nom;
$identity->prenom = $InfosLogin->result->prenom;
2011-04-01 12:14:40 +00:00
$identity->tel = $InfosLogin->result->tel;
$identity->fax = $InfosLogin->result->fax;
$identity->mobile = $InfosLogin->result->mobile;
2011-01-07 17:16:07 +00:00
$identity->id = $InfosLogin->result->id;
$identity->idClient = $InfosLogin->result->idClient;
$identity->reference = $InfosLogin->result->reference;
2011-04-11 14:20:26 +00:00
$identity->nbReponses = $InfosLogin->result->nbReponses;
2011-01-07 17:16:07 +00:00
$identity->typeScore = $InfosLogin->result->typeScore;
2011-01-11 08:43:13 +00:00
$identity->timeout = (!empty($InfosLogin->result->timeout)) ?
$InfosLogin->result->timeout : $this->_timeout;
2011-01-05 15:14:23 +00:00
$identity->ip = $_SERVER['REMOTE_ADDR'];
$identity->modeEdition = false;
2011-01-07 17:16:07 +00:00
$logger = Zend_Registry::get('firebug');
$logger->log($identity, Zend_Log::DEBUG);
if ($InfosLogin->error->errnum!=0){
2011-01-05 15:14:23 +00:00
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity);
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
}