From 6a7903ef056826d3ceee6605d04af8322f5d223b Mon Sep 17 00:00:00 2001 From: Paolo Date: Tue, 18 Jul 2023 16:01:03 +0200 Subject: [PATCH 1/2] - Changed the controller components/SearchBar.php constructor to _not_ start the authentication when the AuthLib is loaded and to check if the user is logged - Added constant ERROR_NOT_AUTH to libraries/SearchBarLib.php --- application/controllers/components/SearchBar.php | 8 ++++++-- application/libraries/SearchBarLib.php | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/application/controllers/components/SearchBar.php b/application/controllers/components/SearchBar.php index dd3c22690..afdc8c4b9 100644 --- a/application/controllers/components/SearchBar.php +++ b/application/controllers/components/SearchBar.php @@ -17,11 +17,15 @@ class SearchBar extends FHC_Controller { parent::__construct(); - // Loads the AuthLib and starts the authentication - $this->load->library('AuthLib'); + // Loads the AuthLib _without_ starting the authentication + // NOTE: a user must be authenticated via another controller to access this one + $this->load->library('AuthLib', array(false)); // Load the library SearchBarLib $this->load->library('SearchBarLib'); + + // Checks if the user is authenticated, otherwise returns an error code in JSON format + if (!isLogged()) $this->terminateWithJsonError(SearchBarLib::ERROR_NOT_AUTH); } //------------------------------------------------------------------------------------------------------------------ diff --git a/application/libraries/SearchBarLib.php b/application/libraries/SearchBarLib.php index 3a9d06d13..751b27145 100644 --- a/application/libraries/SearchBarLib.php +++ b/application/libraries/SearchBarLib.php @@ -30,6 +30,7 @@ class SearchBarLib const ERROR_WRONG_SEARCHSTR = 'ERR002'; const ERROR_NO_TYPES = 'ERR003'; const ERROR_WRONG_TYPES = 'ERR004'; + const ERROR_NOT_AUTH = 'ERR005'; // List of allowed types of search const ALLOWED_TYPES = ['mitarbeiter', 'organisationunit', 'raum', 'person', 'student', 'prestudent', 'document', 'cms']; From 043a2538b77cc578c6d5cae992d470db23c9d069 Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 31 Jul 2023 12:12:59 +0200 Subject: [PATCH 2/2] Updated --- application/controllers/components/SearchBar.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/controllers/components/SearchBar.php b/application/controllers/components/SearchBar.php index afdc8c4b9..d19113177 100644 --- a/application/controllers/components/SearchBar.php +++ b/application/controllers/components/SearchBar.php @@ -18,7 +18,9 @@ class SearchBar extends FHC_Controller parent::__construct(); // Loads the AuthLib _without_ starting the authentication - // NOTE: a user must be authenticated via another controller to access this one + // NOTE: + // - A user must be authenticated via another controller to access this one + // - It is loaded to be able to call the isLogged function later $this->load->library('AuthLib', array(false)); // Load the library SearchBarLib