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:
@@ -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
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user