[module.cas] Created callback (todo: store in SESSION) + [module.*] renamed all with lowercase API path

This commit is contained in:
xdrm-brackets 2018-03-02 09:27:58 +01:00
parent 7dedb80793
commit aadefed195
7 changed files with 115 additions and 54 deletions

View File

@ -0,0 +1,76 @@
<?php
/**
* Created by PhpStorm.
* User: lucas
* Date: 27/02/18
* Time: 16:19
*/
namespace api\module;
use database\core\Repo;
use database\repo\professor;
use error\core\Error;
use error\core\Err;
class casController{
/* (1) Authentication callback
*
* @return professors<array> The professor(s) data
*
---------------------------------------------------------*/
public static function get($args){
// login: https://sso.univ-pau.fr/cas/login?service=http://ptut.com:8080/api/v/1.0/cas
// validate: https://sso.univ-pau.fr/cas/serviceValidate?ticket=***TICKET***&service=http://ptut.com:8080/api/v/1.0/cas
/* (1) Check validity
---------------------------------------------------------*/
/* (1) Check origin */
// TODO
/* (2) Fail if no ticket */
if( !isset($_GET['ticket']) || !is_string($_GET['ticket']) || strlen($_GET['ticket']) < 1 )
return ['error' => new Error(Err::PermissionError, 'missing ticket')];
/* (2) Check ticket (validate)
---------------------------------------------------------*/
/* (1) Build useful variables */
$service = 'http://ptut.com:8080/api/v/1.0/cas';
$ticket = urlencode($_GET['ticket']);
$validate_url = "https://sso.univ-pau.fr/cas/serviceValidate?ticket=$ticket&service=$service";
/* (2) Configure & Prepare CURL */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $validate_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/* (3) Execute CURL & Close it */
$output = curl_exec($ch);
curl_close($ch);
/* (4) Fail if not validated */
if( strpos($output, 'user') === false )
return ['error' => new Error(Err::PermissionError, 'invalid ticket')];
/* (5) Extract cas_login */
$cas_login = trim(strip_tags($output));
/* (6) Check empty */
if( strlen($cas_login) < 1 )
return ['error' => new Error(Err::PermissionError, 'cannot find cas login')];
return ['cas_login' => $cas_login ];
}
}

View File

@ -11,7 +11,7 @@ namespace api\module;
use database\core\Repo; use database\core\Repo;
class CategoryController class categoryController
{ {
public function get($args){ public function get($args){

View File

@ -21,7 +21,7 @@ use error\core\Err;
use error\core\Error; use error\core\Error;
use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Exception;
class ExcelController class excelController
{ {
private const startLineUE = 5; private const startLineUE = 5;

View File

@ -11,7 +11,7 @@ namespace api\module;
use database\core\Repo; use database\core\Repo;
class FormationController class formationController
{ {
public static function get($args){ public static function get($args){

View File

@ -6,13 +6,13 @@
* Time: 16:19 * Time: 16:19
*/ */
namespace api\module\Professor; namespace api\module\professor;
use database\core\Repo; use database\core\Repo;
use database\repo\professor; use database\repo\professor;
class StatsController{ class statsController{
public static function get($args){ public static function get($args){
$idProf = 0; $idProf = 0;
extract($args); extract($args);

View File

@ -14,7 +14,7 @@ use database\repo\professor;
use error\core\Error; use error\core\Error;
use error\core\Err; use error\core\Err;
class ProfessorController{ class professorController{
/* (1) Returns 1 or all professors /* (1) Returns 1 or all professors

View File

@ -7,6 +7,34 @@
} }
}, },
"cas": {
"GET": {
"des": "Authenticatation callback (used by third-party OAuth)",
"per": [],
"par": {}
},
"POST": {
"des": "Login if not already authenticated",
"per": [],
"par": {}
},
"PUT": {
"des": "Check if authenticated",
"per": [],
"par": {}
},
"DELETE": {
"des": "Logout",
"per": [],
"par": {}
}
},
"release": { "release": {
"GET": { "GET": {
@ -21,7 +49,7 @@
} }
}, },
"Excel":{ "excel":{
"POST": { "POST": {
"des": "Import data from an Excel file", "des": "Import data from an Excel file",
"per": [], "per": [],
@ -30,7 +58,7 @@
} }
}, },
"Professor":{ "professor":{
"POST": { "POST": {
"des": "Creates a new professor", "des": "Creates a new professor",
@ -90,7 +118,7 @@
}, },
"Stats": { "stats": {
"GET":{ "GET":{
"des": "Get statistics of the professor", "des": "Get statistics of the professor",
"per": [], "per": [],
@ -103,7 +131,7 @@
}, },
"Formation": { "formation": {
"GET":{ "GET":{
"des": "Get all data about a formation", "des": "Get all data about a formation",
"per": [], "per": [],
@ -113,7 +141,7 @@
} }
}, },
"Category": { "category": {
"GET": { "GET": {
"des" : "Get all data about a professor category", "des" : "Get all data about a professor category",
"per": [], "per": [],
@ -121,48 +149,5 @@
"URL0":{"des" : "Id of the category", "typ": "id", "ren": "idCat", "opt" : true} "URL0":{"des" : "Id of the category", "typ": "id", "ren": "idCat", "opt" : true}
} }
} }
},
"a": {
"b": {
"c": {
"PUT": {
"des": "PUT A/B/C.",
"per": [],
"par": {}
},
"DELETE": {
"des": "DELETE A/B/C.",
"per": [],
"par": {}
}
},
"PUT": {
"des": "PUT A/B.",
"per": [],
"par": {}
},
"DELETE": {
"des": "DELETE A/B.",
"per": [],
"par": {}
}
},
"GET": {
"des": "GET A.",
"per": [],
"par": {}
},
"POST": {
"des": "POST A.",
"per": [],
"par": {}
}
} }
} }