extranet/library/Web/WebAuthAdapter.php

58 lines
2.2 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;
2011-09-07 14:14:25 +00:00
$identity->password = $this->_password;
2011-09-07 12:54:43 +00:00
$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
if ( is_string($InfosLogin) || $InfosLogin->error->errnum!=0){
$message = $InfosLogin;
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
}