2014-12-09 11:28:12 +00:00
|
|
|
<?php
|
|
|
|
class AuthController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
protected $partnerConfig = array(
|
|
|
|
'inextenso' => array(
|
2014-12-11 15:53:39 +00:00
|
|
|
'logo' => 'logo-in-extenso.gif',
|
2014-12-12 10:04:17 +00:00
|
|
|
'clientId' => 193,
|
2014-12-09 11:28:12 +00:00
|
|
|
'serviceCode' => 'SSO',
|
|
|
|
'authType' => 'userSSO',
|
|
|
|
'login' => 'MAIL',
|
|
|
|
'token' => 'token',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Point d'entrée pour les connexions partenaires.
|
|
|
|
* L'utilisateur s'identifie sur son portail habituel.
|
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
//Désactiver le layout
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
|
2014-12-11 15:53:39 +00:00
|
|
|
$this->view->headLink()->appendStylesheet('/themes/default/styles/user.css', 'all');
|
|
|
|
|
2014-12-09 11:28:12 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get partner name - see route in bootstrap
|
|
|
|
*/
|
|
|
|
$partner = $request->getParam('partner');
|
2014-12-11 15:53:39 +00:00
|
|
|
if ( array_key_exists($partner, $this->partnerConfig) ) {
|
|
|
|
$config = $this->partnerConfig[$partner];
|
|
|
|
$this->view->logo = $config['logo'];
|
2014-12-09 11:28:12 +00:00
|
|
|
$params = $request->getParams();
|
|
|
|
$objectParams = array();
|
|
|
|
foreach ($params as $label => $value) {
|
|
|
|
$object = new stdClass();
|
|
|
|
$object->label = $label;
|
|
|
|
$object->value = $value;
|
|
|
|
$objectParams[] = $object;
|
|
|
|
}
|
2014-12-11 15:53:39 +00:00
|
|
|
$login = $params[$config['login']];
|
2014-12-09 11:28:12 +00:00
|
|
|
$part = strstr($login, '@', true);
|
|
|
|
if ($part !== false) {
|
|
|
|
$login = $part;
|
|
|
|
}
|
2014-12-11 15:53:39 +00:00
|
|
|
$token = $params[$config['token']];
|
2014-12-09 11:28:12 +00:00
|
|
|
try {
|
2014-12-11 15:53:39 +00:00
|
|
|
$ws = new Scores_Ws_Client('gestion', '0.4');
|
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->client = $config['clientId'];
|
|
|
|
$parameters->login = $login;
|
|
|
|
$parameters->token = $token;
|
|
|
|
$parameters->params = $objectParams;
|
|
|
|
$hash = $ws->ssoAuthenticate($parameters);
|
2014-12-09 11:28:12 +00:00
|
|
|
//Utilisateur inexistant
|
2014-12-11 15:53:39 +00:00
|
|
|
if ($hash === 'false' ) {
|
2014-12-09 11:28:12 +00:00
|
|
|
$this->view->NoUser = true;
|
|
|
|
//Set form value
|
2014-12-12 10:04:17 +00:00
|
|
|
$this->view->FormPname = $partner;
|
2014-12-09 11:28:12 +00:00
|
|
|
$this->view->FormIdentifiant = $login;
|
|
|
|
$this->view->FormCourriel = $request->getParam('MAIL');
|
|
|
|
$this->view->FormSiret = $request->getParam('SIRET');
|
|
|
|
$this->view->FormNom = $request->getParam('LASTNAME');
|
|
|
|
$this->view->FormPrenom = $request->getParam('FIRSTNAME');
|
|
|
|
}
|
|
|
|
//Redirection
|
|
|
|
else {
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
//First set partial identity
|
|
|
|
$identity = new stdClass();
|
|
|
|
$identity->username = $login;
|
|
|
|
$identity->password = $hash;
|
|
|
|
$auth->getStorage()->write($identity);
|
|
|
|
$adressIp = $_SERVER['REMOTE_ADDR'];
|
2014-12-11 15:53:39 +00:00
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->login = $login;
|
|
|
|
$parameters->ipUtiliateur = $adressIp;
|
2014-12-12 10:04:17 +00:00
|
|
|
try {
|
|
|
|
$ws = new Scores_Ws_Client('gestion', '0.3');
|
|
|
|
$InfosLogin = $ws->getInfosLogin($parameters);
|
|
|
|
if ( is_string($InfosLogin) || $InfosLogin->error->errnum != 0 ) {
|
|
|
|
$this->view->Error = true;
|
|
|
|
} else {
|
|
|
|
$user = new Scores_Utilisateur();
|
|
|
|
$identity = $user->updateProfil($InfosLogin);
|
|
|
|
$auth->getStorage()->write($identity);
|
|
|
|
//Redirect
|
|
|
|
$this->redirect('/');
|
|
|
|
}
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
switch ( $e->getCode() ) {
|
|
|
|
case 'MSG':
|
|
|
|
$this->view->Message = $e->getMessage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->view->Error = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-09 11:28:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
switch ( $e->getCode() ) {
|
|
|
|
case 'MSG':
|
|
|
|
$this->view->Message = $e->getMessage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->view->Error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->view->Message = "Erreur dans les paramètres.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 15:53:39 +00:00
|
|
|
/**
|
|
|
|
* Creation d'un utilisateur en SSO
|
|
|
|
*/
|
2014-12-09 11:28:12 +00:00
|
|
|
public function userssocreateAction()
|
|
|
|
{
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
|
2014-12-12 10:04:17 +00:00
|
|
|
$request = $this->getRequest();
|
2014-12-11 15:53:39 +00:00
|
|
|
|
2014-12-12 10:04:17 +00:00
|
|
|
$partner = $request->getParam('partner');
|
|
|
|
if ( array_key_exists($partner, $this->partnerConfig) ) {
|
|
|
|
$config = $this->partnerConfig[$partner];
|
|
|
|
$this->view->logo = $config['logo'];
|
|
|
|
$data = array(
|
|
|
|
'idClient' => $config['clientId'],
|
|
|
|
'login' => $request->getParam('login'),
|
|
|
|
'email' => $request->getParam('email', ''),
|
|
|
|
'actif' => 1,
|
|
|
|
'nom' => $request->getParam('nom', ''),
|
|
|
|
'prenom' => $request->getParam('prenom', ''),
|
|
|
|
'siret' => str_replace(' ', '', $request->getParam('siret', '')),
|
|
|
|
'tel' => str_replace(array(' ','.'), array('',''), $request->getParam('tel', '')),
|
|
|
|
'Service' => $config['serviceCode'],
|
|
|
|
);
|
2014-12-11 15:53:39 +00:00
|
|
|
|
2014-12-12 10:04:17 +00:00
|
|
|
try {
|
|
|
|
$ws = new Scores_Ws_Client('gestion', '0.4');
|
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->data = json_encode($data);
|
|
|
|
$created = $ws->setUserSSO($parameters);
|
|
|
|
if ($created === false ) {
|
|
|
|
$this->view->Message = "Erreur lors de la création de votre compte.";
|
|
|
|
} else {
|
|
|
|
$this->view->UserCreated = true;
|
|
|
|
//First set partial identity
|
|
|
|
$identity = new stdClass();
|
|
|
|
$identity->username = $login;
|
|
|
|
$identity->password = $hash;
|
|
|
|
$auth->getStorage()->write($identity);
|
|
|
|
$adressIp = $_SERVER['REMOTE_ADDR'];
|
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->login = $login;
|
|
|
|
$parameters->ipUtiliateur = $adressIp;
|
|
|
|
try {
|
|
|
|
$ws = new Scores_Ws_Client('gestion', '0.3');
|
|
|
|
$InfosLogin = $ws->getInfosLogin($parameters);
|
|
|
|
if ( is_string($InfosLogin) || $InfosLogin->error->errnum != 0 ) {
|
|
|
|
$this->view->Error = true;
|
|
|
|
} else {
|
|
|
|
$user = new Scores_Utilisateur();
|
|
|
|
$identity = $user->updateProfil($InfosLogin);
|
|
|
|
$auth->getStorage()->write($identity);
|
|
|
|
}
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
switch ( $e->getCode() ) {
|
|
|
|
case 'MSG':
|
|
|
|
$this->view->Message = $e->getMessage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->view->Error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
switch ( $e->getCode() ) {
|
|
|
|
case 'MSG':
|
|
|
|
$this->view->Message = $e->getMessage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->view->Error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-11 15:53:39 +00:00
|
|
|
|
2014-12-12 10:04:17 +00:00
|
|
|
} else {
|
|
|
|
$this->view->Message = "Erreur dans les paramètres.";
|
|
|
|
}
|
2014-12-09 11:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lien de validation depuis email
|
|
|
|
* Paramètres
|
|
|
|
* - login ou email
|
|
|
|
* - key
|
|
|
|
* L'action renvoi sur un affichage spécifique suivant le type de client
|
|
|
|
*/
|
|
|
|
public function validateAction()
|
|
|
|
{
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
//Validation en erreur
|
|
|
|
|
|
|
|
//Validation invalide
|
|
|
|
|
|
|
|
//Validation Ok => Comment afficher les particularités
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|