2014-12-09 11:28:12 +00:00
|
|
|
<?php
|
|
|
|
class AuthController extends Zend_Controller_Action
|
|
|
|
{
|
2015-07-08 13:48:28 +00:00
|
|
|
protected $theme;
|
|
|
|
|
2014-12-09 11:28:12 +00:00
|
|
|
protected $partnerConfig = array(
|
|
|
|
'inextenso' => array(
|
2014-12-11 15:53:39 +00:00
|
|
|
'logo' => 'logo-in-extenso.gif',
|
2014-12-19 12:49:03 +00:00
|
|
|
'clientId' => 195,
|
2014-12-09 11:28:12 +00:00
|
|
|
'serviceCode' => 'SSO',
|
|
|
|
'authType' => 'userSSO',
|
2015-05-18 15:13:49 +00:00
|
|
|
'login' => 'mail',
|
2014-12-09 11:28:12 +00:00
|
|
|
'token' => 'token',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2015-07-08 20:38:22 +00:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
// --- Theme
|
|
|
|
$this->theme = Zend_Registry::get('theme');
|
|
|
|
}
|
|
|
|
|
2014-12-09 11:28:12 +00:00
|
|
|
/**
|
|
|
|
* Point d'entrée pour les connexions partenaires.
|
|
|
|
* L'utilisateur s'identifie sur son portail habituel.
|
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2015-10-27 08:31:20 +00:00
|
|
|
// --- Désactiver le layout
|
2014-12-09 11:28:12 +00:00
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
|
2015-10-27 08:31:20 +00:00
|
|
|
$this->view->headLink()
|
|
|
|
->appendStylesheet($this->theme->pathStyle.'/inexweb.css', 'all')
|
|
|
|
->appendStylesheet($this->theme->pathStyle.'/user.css', 'all');
|
2014-12-11 15:53:39 +00:00
|
|
|
|
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) {
|
2015-01-13 19:59:31 +00:00
|
|
|
if (in_array($label, array('controller', 'action'))) continue;
|
|
|
|
$object = new stdClass();
|
|
|
|
$object->label = $label;
|
|
|
|
$object->value = $value;
|
|
|
|
$objectParams[] = $object;
|
2014-12-09 11:28:12 +00:00
|
|
|
}
|
2015-01-13 19:59:31 +00:00
|
|
|
$this->view->Params = $objectParams;
|
2015-07-08 13:48:28 +00:00
|
|
|
|
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']];
|
2015-07-08 13:48:28 +00:00
|
|
|
|
2014-12-09 11:28:12 +00:00
|
|
|
try {
|
2014-12-11 15:53:39 +00:00
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->client = $config['clientId'];
|
|
|
|
$parameters->login = $login;
|
|
|
|
$parameters->token = $token;
|
|
|
|
$parameters->params = $objectParams;
|
2016-12-22 11:34:59 +01:00
|
|
|
$ws = new Scores_Ws_Client('account', '0.1');
|
2014-12-11 15:53:39 +00:00
|
|
|
$hash = $ws->ssoAuthenticate($parameters);
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- Utilisateur inexistant
|
|
|
|
if ( $hash === 'false' || $hash === false ) {
|
2014-12-09 11:28:12 +00:00
|
|
|
$this->view->NoUser = true;
|
2015-10-27 08:31:20 +00:00
|
|
|
$urlParams = array('controller'=>'auth', 'action'=>'userssoform');
|
|
|
|
$urlParams = array_merge($params, $urlParams);
|
|
|
|
$this->view->FormUrlParams = $urlParams;
|
2014-12-09 11:28:12 +00:00
|
|
|
}
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- Redirection
|
2014-12-09 11:28:12 +00:00
|
|
|
else {
|
2015-07-08 13:48:28 +00:00
|
|
|
|
2015-01-13 19:59:31 +00:00
|
|
|
$auth = Zend_Auth::getInstance();
|
2015-07-08 13:48:28 +00:00
|
|
|
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- Set partial identity
|
2014-12-09 11:28:12 +00:00
|
|
|
$identity = new stdClass();
|
|
|
|
$identity->username = $login;
|
|
|
|
$identity->password = $hash;
|
|
|
|
$auth->getStorage()->write($identity);
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- End Set partial identity
|
2015-07-08 13:48:28 +00:00
|
|
|
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- Get InfosLogin
|
2014-12-09 11:28:12 +00:00
|
|
|
$adressIp = $_SERVER['REMOTE_ADDR'];
|
2014-12-11 15:53:39 +00:00
|
|
|
$parameters = new stdClass();
|
|
|
|
$parameters->login = $login;
|
2015-01-13 19:59:31 +00:00
|
|
|
$parameters->ipUtilisateur = $adressIp;
|
2015-08-31 12:18:19 +00:00
|
|
|
$parameters->from = 'auth';
|
2014-12-12 10:04:17 +00:00
|
|
|
try {
|
|
|
|
$ws = new Scores_Ws_Client('gestion', '0.3');
|
|
|
|
$InfosLogin = $ws->getInfosLogin($parameters);
|
2015-01-13 19:59:31 +00:00
|
|
|
Zend_Registry::get('firebug')->info($InfosLogin);
|
2014-12-12 10:04:17 +00:00
|
|
|
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);
|
2015-10-27 08:31:20 +00:00
|
|
|
// --- Redirect
|
2014-12-12 10:04:17 +00:00
|
|
|
$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
|
|
|
}
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- End Get InfosLogin
|
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.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:31:20 +00:00
|
|
|
/**
|
|
|
|
* Affichage du formulaire pour l'inscription des utilisateurs
|
|
|
|
*/
|
|
|
|
public function userssoformAction()
|
|
|
|
{
|
|
|
|
// --- Désactiver le layout
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->view->headLink()->appendStylesheet($this->theme->pathStyle.'/user.css', 'all');
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get partner name - see route in bootstrap
|
|
|
|
*/
|
|
|
|
$partner = $request->getParam('partner');
|
|
|
|
if ( array_key_exists($partner, $this->partnerConfig) ) {
|
|
|
|
$config = $this->partnerConfig[$partner];
|
|
|
|
$this->view->logo = $config['logo'];
|
|
|
|
$params = $request->getParams();
|
|
|
|
$objectParams = array();
|
|
|
|
foreach ($params as $label => $value) {
|
|
|
|
if (in_array($label, array('controller', 'action'))) continue;
|
|
|
|
$object = new stdClass();
|
|
|
|
$object->label = $label;
|
|
|
|
$object->value = $value;
|
|
|
|
$objectParams[] = $object;
|
|
|
|
}
|
|
|
|
$this->view->Params = $objectParams;
|
|
|
|
|
|
|
|
$login = $params[$config['login']];
|
|
|
|
$part = strstr($login, '@', true);
|
|
|
|
if ($part !== false) {
|
|
|
|
$login = $part;
|
|
|
|
}
|
|
|
|
$token = $params[$config['token']];
|
|
|
|
|
|
|
|
$this->view->NoUser = true;
|
|
|
|
// --- Set form value
|
|
|
|
$this->view->FormPartner = $partner;
|
|
|
|
$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('name');
|
|
|
|
}
|
|
|
|
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 {
|
2016-10-24 11:27:06 +02:00
|
|
|
$ws = new Scores_Ws_Client('account', '0.1');
|
2014-12-12 10:04:17 +00:00
|
|
|
$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;
|
2015-01-13 19:59:31 +00:00
|
|
|
// --- Data to go back
|
|
|
|
$params = $request->getParams();
|
|
|
|
$urlArgs = array();
|
|
|
|
foreach ($params as $label => $value) {
|
|
|
|
if (in_array($label, array('controller', 'action'))) continue;
|
|
|
|
if (substr($label, 0, 2) == 'P-') {
|
|
|
|
$urlArgs[substr($label, 2)] = $value;
|
|
|
|
}
|
2014-12-12 10:04:17 +00:00
|
|
|
}
|
2015-01-13 19:59:31 +00:00
|
|
|
$urlArgs['partner'] = 'inextenso';
|
|
|
|
$this->view->UrlArgs = $urlArgs;
|
2014-12-12 10:04:17 +00:00
|
|
|
}
|
|
|
|
} 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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|