fix(router): support case-insensitive route URLs and token query parameters

This commit is contained in:
Philipp Urbschat 2026-09-12 23:26:11 +02:00
parent d970270d91
commit 71fed56884
Signed by: Phili
SSH key fingerprint: SHA256:ZSQWnldzrYiABzOV6vTICPe0h19pTpus7sCbm2S0po0
3 changed files with 18 additions and 12 deletions

View file

@ -3,7 +3,7 @@ require_once __DIR__ . '/../../core/Controller.php';
class RegisterController extends Controller {
public function index($urlToken = null) {
$token = trim($_GET['token'] ?? $urlToken ?? '');
$token = trim($_GET['token'] ?? $_GET['TOKEN'] ?? $urlToken ?? '');
if (empty($token)) {
$this->view('register', [
@ -50,7 +50,7 @@ class RegisterController extends Controller {
exit;
}
$token = trim($_POST['token'] ?? '');
$token = trim($_POST['token'] ?? $_POST['TOKEN'] ?? '');
$name = trim($_POST['name'] ?? '');
$email = trim(strtolower($_POST['email'] ?? ''));
$password = $_POST['password'] ?? '';

View file

@ -24,7 +24,7 @@ class Invitation {
}
public function getByToken(string $token): ?array {
$sql = "SELECT * FROM home_invitations WHERE token = :token";
$sql = "SELECT * FROM home_invitations WHERE LOWER(token) = LOWER(:token)";
$this->db->query($sql);
$this->db->bind(':token', $token);
$invitation = $this->db->single();
@ -52,7 +52,7 @@ class Invitation {
}
public function recordUse(string $token): bool {
$sql = "UPDATE home_invitations SET uses_count = uses_count + 1 WHERE token = :token";
$sql = "UPDATE home_invitations SET uses_count = uses_count + 1 WHERE LOWER(token) = LOWER(:token)";
$this->db->query($sql);
$this->db->bind(':token', $token);
return $this->db->execute();

View file

@ -7,19 +7,25 @@ class Router {
public function route() {
$url = $this->parseUrl();
$controllerPath = __DIR__ . '/../app/controllers/';
// Controller Check
if (isset($url[0]) && file_exists($controllerPath . ucfirst($url[0]) . 'Controller.php')) {
$this->controller = ucfirst($url[0]) . 'Controller';
unset($url[0]);
// Controller Check (Case-insensitive)
if (isset($url[0])) {
$candidate = ucfirst(strtolower($url[0])) . 'Controller';
if (file_exists($controllerPath . $candidate . '.php')) {
$this->controller = $candidate;
unset($url[0]);
}
}
require_once $controllerPath . $this->controller . '.php';
$this->controller = new $this->controller;
// Method Check
// Method Check (Case-insensitive)
if (isset($url[1])) {
$candidateMethod = $url[1];
if (is_callable([$this->controller, $candidateMethod]) && strpos($candidateMethod, '_') !== 0) {
$this->method = $candidateMethod;
unset($url[1]);
foreach (get_class_methods($this->controller) as $methodName) {
if (strcasecmp($methodName, $candidateMethod) === 0 && strpos($methodName, '_') !== 0) {
$this->method = $methodName;
unset($url[1]);
break;
}
}
}
// Params & Execution