extranet/application/controllers/AuthController.php
2014-12-11 15:53:39 +00:00

137 lines
4.6 KiB
PHP

<?php
class AuthController extends Zend_Controller_Action
{
protected $partnerConfig = array(
'inextenso' => array(
'logo' => 'logo-in-extenso.gif',
'clientId' => 0,
'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();
$this->view->headLink()->appendStylesheet('/themes/default/styles/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) {
$object = new stdClass();
$object->label = $label;
$object->value = $value;
$objectParams[] = $object;
}
$login = $params[$config['login']];
$part = strstr($login, '@', true);
if ($part !== false) {
$login = $part;
}
$token = $params[$config['token']];
try {
$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);
//Utilisateur inexistant
if ($hash === 'false' ) {
$this->view->NoUser = true;
//Set form value
$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'];
$ws = new Scores_Ws_Client('gestion', '0.3');
$parameters = new stdClass();
$parameters->login = $login;
$parameters->ipUtiliateur = $adressIp;
$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;
}
}
} else {
$this->view->Message = "Erreur dans les paramètres.";
}
}
/**
* Creation d'un utilisateur en SSO
*/
public function userssocreateAction()
{
$this->_helper->layout()->disableLayout();
}
/**
* 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
}
}