From e67195871f3004b04652fb46a4d16b517574ff13 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 20 Mar 2018 10:19:32 +0100 Subject: [PATCH] [module.cas] dispatch custom error codes [webpack.login] display error codes --- build/api/module/casController.php | 18 +++++++++--------- webpack/page/login.js | 25 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/build/api/module/casController.php b/build/api/module/casController.php index b18223a..d2c6e2e 100644 --- a/build/api/module/casController.php +++ b/build/api/module/casController.php @@ -48,9 +48,9 @@ class casController{ /* (0) Initialize ---------------------------------------------------------*/ /* (1) Global DOWNLOAD data */ - $headers = ['Content-Type' => 'text/html; charset=UTF-8' ]; + $headers = ['Content-Type' => 'text/html; charset=UTF-8' ]; $body_start = "Veuillez patienter...
Vous allez être redirigés"; + $body_end = ");window.close();"; /* (2) Reset SESSION */ $_SESSION['CAS'] = []; @@ -71,15 +71,15 @@ class casController{ /* (2) Fail if no ticket */ 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) ---------------------------------------------------------*/ /* (1) Build useful variables */ - $service = ($_SERVER['SERVER_NAME'] == 'ptut.com' ) ? 'http' : 'https'; - $service .= '://'.$_SERVER['HTTP_HOST'].'/api/v/1.0/cas'; + $service = ($_SERVER['SERVER_NAME'] == 'ptut.com' ) ? 'http' : 'https'; + $service .= '://'.$_SERVER['HTTP_HOST'].'/api/v/1.0/cas'; $ticket = urlencode($_GET['ticket']); $validate_url = "https://sso.univ-pau.fr/cas/serviceValidate?ticket=$ticket&service=$service"; @@ -95,14 +95,14 @@ class casController{ /* (4) Fail if not validated */ 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 */ $cas_login = trim(strip_tags($output)); /* (6) Check empty */ 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 */ 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 */ $_SESSION['AvailableDepartment'] = $departments; @@ -137,7 +137,7 @@ class casController{ /* (2) If not found -> reset SESSION */ 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 ]; diff --git a/webpack/page/login.js b/webpack/page/login.js index 9327d76..66cc06f 100644 --- a/webpack/page/login.js +++ b/webpack/page/login.js @@ -42,8 +42,31 @@ window.cas_callback = function(cas_login){ 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.
(errcode: no_ticket_received)'; + break; + case -2: + gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.
(errcode: cas_not_authed)'; + break; + case -3: + gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.
(errcode: no_meta_department)'; + break; + case -4: + gstore.get.login_error_text = 'Erreur de connexion. Veuillez réessayer.
(errcode: no_matching_professor)'; + break; + + } + + setTimeout(function(){ gstore.get.login_class = 'neutral'; }, 1500); + /* (4) If login -> reload page */ - }else{ + }else{{ gstore.get.login_error_text = 'Vous êtes connectés. Vous allez être redirigé.'; gstore.get.login_class = 'valid';