Refactor return types and add password handling logic.

Updated return types from `language_pack_i` to `object` for flexibility. Enhanced `parseUsers` to convert empty passwords into booleans for better data representation. Added a new endpoint to list number plate scans with proper logging and session validation.
This commit is contained in:
Jepp9350
2025-01-23 13:14:41 +01:00
parent 58c50233d5
commit 576d43bbfe
3 changed files with 35 additions and 4 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ class language_packs
* Get the default language pack
* @return language_pack_i The default language pack
*/
public function getDefaultLanguagePack(): language_pack_i
public function getDefaultLanguagePack(): object
{
return $this->getLanguagePack($this->default_language);
}
@@ -46,7 +46,7 @@ class language_packs
* @return language_pack_i The language pack
*/
public function getLanguagePack(string $language): language_pack_i
public function getLanguagePack(string $language): object
{
foreach ( $this->language_packs as $language_pack ) {
if ($language_pack->getLanguage() === $language) {
+11 -2
View File
@@ -689,9 +689,18 @@ class users_o extends db
return false;
}
public function parseUsers(array $listObjectsWithPaginationIfSet): array
public function parseUsers(array $listObjectsWithPaginationIfSet, $variables = []): array
{
return self::parseCustomerNumbers($listObjectsWithPaginationIfSet);
$tmp = self::parseCustomerNumbers($listObjectsWithPaginationIfSet);
// Check if the user has a password, and change it to a boolean instead of a string
foreach ( $tmp as $key => $value ) {
if ($value['password'] === '') {
$tmp[$key]['password'] = false;
} else {
$tmp[$key]['password'] = true;
}
}
return $tmp;
}
public function parseCustomerNumbers(array $listObjectsWithPaginationIfSet): array
+22
View File
@@ -68,5 +68,27 @@ class plateScansRoute
$response->error('Invalid session', 400);
}
});
$this->get('/numberplatescans', function () {
// Require the user to be logged in
global $response;
$this->requirePermission('list_number_plate_scans');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Get the number plate scans
$number_plate_scans = (new plate_scans_o())->listObjectsWithPaginationIfSet();
// Log the incident
(new logs_o())->add('numberplatescans', 'global', 1, $user->id, 'LIST_NUMBER_PLATE_SCANS', 'Successfully listed number plate scans');
// Return the number plate scans
$response->success($number_plate_scans);
} else {
// Log the incident
(new logs_o())->add('numberplatescans', 'global', 1, 0, 'LIST_NUMBER_PLATE_SCANS', 'No user found, or invalid session');
// Return an error
$response->error('Invalid session', 400);
}
});
}
}