From 2a9e1e1474cc7c1e3e6d97e4b7abbeeb0333863e Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 15 Mar 2018 12:02:28 +0100 Subject: [PATCH] Implemented department database switch --- build/api/core/AuthSystemDefault.php | 4 ++ build/api/module/departementController.php | 45 ++++++++++++++++++++++ config/modules.json | 8 ++++ 3 files changed, 57 insertions(+) create mode 100644 build/api/module/departementController.php diff --git a/build/api/core/AuthSystemDefault.php b/build/api/core/AuthSystemDefault.php index 58b9ece..1a2ceac 100644 --- a/build/api/core/AuthSystemDefault.php +++ b/build/api/core/AuthSystemDefault.php @@ -38,6 +38,7 @@ /* (2) Get professor with this login */ $deps = $prof_repo->getLinkedDepartment($_SESSION['CAS']['login']); if(is_array($deps)){ + $_SESSION["AvailableDepartment"] = $deps; $_SESSION['CurrentDatabase'] = $deps[0]["dbName"]; $_SESSION['CurrentDepartementId'] = $deps[0]["idDep"]; @@ -48,6 +49,9 @@ /* (3) If found -> store useful information */ if( is_array($by_login) && isset($by_login['idProfesseur']) && isset($by_login['admin']) ){ + //security + session_regenerate_id(); + $_SESSION['CAS']['admin'] = (bool) $by_login['admin']; $_SESSION['CAS']['id'] = (int) $by_login['idProfesseur']; $_SESSION["isLogged"] = true; diff --git a/build/api/module/departementController.php b/build/api/module/departementController.php new file mode 100644 index 0000000..d312128 --- /dev/null +++ b/build/api/module/departementController.php @@ -0,0 +1,45 @@ +getLinkedDepartment($_SESSION['CAS']['login']); + + if(is_array($deps)){ + foreach ($deps as $dep){ + if($dep["idDep"] == $department){ + $_SESSION["AvailableDepartment"] = $deps; + $_SESSION['CurrentDatabase'] = $dep["dbName"]; + $_SESSION['CurrentDepartementId'] = $dep["idDep"]; + + return ["success" => true]; + } + } + } + + return ["success" => false]; + + } + +} \ No newline at end of file diff --git a/config/modules.json b/config/modules.json index 103e37c..ec622c8 100644 --- a/config/modules.json +++ b/config/modules.json @@ -72,6 +72,14 @@ }, "departement":{ + + "PUT":{ + "des": "Switch the user on another department database", + "per": [], + "par": { + "department": {"des": "Department id", "typ": "id"} + } + }, "errors":{ "GET": { "des": "Get the list of incoherence of the department",