Fixed a bug when no authorization token was provided.
This commit is contained in:
@@ -3,10 +3,8 @@
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use classes\encrypt;
|
||||
use objects\logs_o;
|
||||
use objects\tokens_o;
|
||||
use objects\users_o;
|
||||
use traits\route_t;
|
||||
|
||||
class authRoute
|
||||
@@ -20,8 +18,12 @@ class authRoute
|
||||
global $response;
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
// Check if the customer number, and password are set
|
||||
if (!isset($data['customer_number'])) { $response->error('Customer number is required', 400); }
|
||||
if (!isset($data['password'])) { $response->error('Password is required', 400); }
|
||||
if (!isset($data['customer_number'])) {
|
||||
$response->error('Customer number is required', 400);
|
||||
}
|
||||
if (!isset($data['password'])) {
|
||||
$response->error('Password is required', 400);
|
||||
}
|
||||
// Try to log the user in
|
||||
$isCredentialsValid = (new authentication())->authenticate($data['customer_number'], $data['password']);
|
||||
// Log the incident
|
||||
@@ -40,7 +42,7 @@ class authRoute
|
||||
$this->get('/auth/logout', function () {
|
||||
// Get the token from the headers
|
||||
global $response;
|
||||
$token = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
$token = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
|
||||
// Remove the Bearer prefix
|
||||
$token = str_replace('Bearer ', '', $token);
|
||||
// Check if the token is valid
|
||||
@@ -56,7 +58,7 @@ class authRoute
|
||||
$this->get('/auth/session', function () {
|
||||
// Get the token from the headers
|
||||
global $response;
|
||||
$token = $_SERVER['HTTP_AUTHORIZATION'];
|
||||
$token = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; // Default to empty string if not set
|
||||
// Remove the Bearer prefix
|
||||
$token = str_replace('Bearer ', '', $token);
|
||||
// Check if the token is valid
|
||||
|
||||
Reference in New Issue
Block a user