[module.cas] dispatch custom error codes [webpack.login] display error codes

This commit is contained in:
xdrm-brackets 2018-03-20 10:19:32 +01:00
parent 14c71d88f1
commit e67195871f
2 changed files with 33 additions and 10 deletions

View File

@ -48,9 +48,9 @@ class casController{
/* (0) Initialize /* (0) Initialize
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Global DOWNLOAD data */ /* (1) Global DOWNLOAD data */
$headers = ['Content-Type' => 'text/html; charset=UTF-8' ]; $headers = ['Content-Type' => 'text/html; charset=UTF-8' ];
$body_start = "Veuillez patienter...<br>Vous allez être redirigés<script type='text/javascript'>( typeof window.opener.cas_callback === 'function' ) && window.opener.cas_callback("; $body_start = "Veuillez patienter...<br>Vous allez être redirigés<script type='text/javascript'>( typeof window.opener.cas_callback === 'function' ) && window.opener.cas_callback(";
$body_end = ");window.close();</script>"; $body_end = ");window.close();</script>";
/* (2) Reset SESSION */ /* (2) Reset SESSION */
$_SESSION['CAS'] = []; $_SESSION['CAS'] = [];
@ -71,15 +71,15 @@ class casController{
/* (2) Fail if no ticket */ /* (2) Fail if no ticket */
if( !isset($_GET['ticket']) || !is_string($_GET['ticket']) || strlen($_GET['ticket']) < 1 ) if( !isset($_GET['ticket']) || !is_string($_GET['ticket']) || strlen($_GET['ticket']) < 1 )
return [ 'headers' => $headers, 'body' => $body_start.'null'.$body_end ]; return [ 'headers' => $headers, 'body' => $body_start.'-1'.$body_end ];
/* (2) Check ticket (validate) /* (2) Check ticket (validate)
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Build useful variables */ /* (1) Build useful variables */
$service = ($_SERVER['SERVER_NAME'] == 'ptut.com' ) ? 'http' : 'https'; $service = ($_SERVER['SERVER_NAME'] == 'ptut.com' ) ? 'http' : 'https';
$service .= '://'.$_SERVER['HTTP_HOST'].'/api/v/1.0/cas'; $service .= '://'.$_SERVER['HTTP_HOST'].'/api/v/1.0/cas';
$ticket = urlencode($_GET['ticket']); $ticket = urlencode($_GET['ticket']);
$validate_url = "https://sso.univ-pau.fr/cas/serviceValidate?ticket=$ticket&service=$service"; $validate_url = "https://sso.univ-pau.fr/cas/serviceValidate?ticket=$ticket&service=$service";
@ -95,14 +95,14 @@ class casController{
/* (4) Fail if not validated */ /* (4) Fail if not validated */
if( strpos($output, 'user') === false ) if( strpos($output, 'user') === false )
return [ 'headers' => $headers, 'body' => $body_start.'null'.$body_end ]; return [ 'headers' => $headers, 'body' => $body_start.'-2'.$body_end ];
/* (5) Extract cas_login */ /* (5) Extract cas_login */
$cas_login = trim(strip_tags($output)); $cas_login = trim(strip_tags($output));
/* (6) Check empty */ /* (6) Check empty */
if( strlen($cas_login) < 1 ) if( strlen($cas_login) < 1 )
return [ 'headers' => $headers, 'body' => $body_start.'null'.$body_end ]; return [ 'headers' => $headers, 'body' => $body_start.'-2'.$body_end ];
@ -116,7 +116,7 @@ class casController{
/* (2) Failure: if no department for @cas_login */ /* (2) Failure: if no department for @cas_login */
if( count($departments) === 0 ) if( count($departments) === 0 )
return [ 'headers' => $headers, 'body' => $body_start.'null'.$body_end ]; return [ 'headers' => $headers, 'body' => $body_start.'-3'.$body_end ];
/* (3) Set departments data */ /* (3) Set departments data */
$_SESSION['AvailableDepartment'] = $departments; $_SESSION['AvailableDepartment'] = $departments;
@ -137,7 +137,7 @@ class casController{
/* (2) If not found -> reset SESSION */ /* (2) If not found -> reset SESSION */
if( !is_array($by_login) || !isset($by_login['idProfesseur']) || !isset($by_login['admin']) ) if( !is_array($by_login) || !isset($by_login['idProfesseur']) || !isset($by_login['admin']) )
return [ 'headers' => $headers, 'body' => $body_start.'null'.$body_end ]; return [ 'headers' => $headers, 'body' => $body_start.'-4'.$body_end ];

View File

@ -42,8 +42,31 @@ window.cas_callback = function(cas_login){
setTimeout(function(){ gstore.get.login_class = 'neutral'; }, 1500); setTimeout(function(){ gstore.get.login_class = 'neutral'; }, 1500);
/* (4) If error code -> display error */
}else if( !isNaN(cas_login) ){
gstore.get.login_class = 'invalid';
switch(cas_login){
case -1:
gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.<br>(errcode: no_ticket_received)';
break;
case -2:
gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.<br>(errcode: cas_not_authed)';
break;
case -3:
gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.<br>(errcode: no_meta_department)';
break;
case -4:
gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.<br>(errcode: no_matching_professor)';
break;
}
setTimeout(function(){ gstore.get.login_class = 'neutral'; }, 1500);
/* (4) If login -> reload page */ /* (4) If login -> reload page */
}else{ }else{{
gstore.get.login_error_text = 'Vous êtes connectés. Vous allez être redirigé.'; gstore.get.login_error_text = 'Vous êtes connectés. Vous allez être redirigé.';
gstore.get.login_class = 'valid'; gstore.get.login_class = 'valid';