diff --git a/exam/api/Login/Login.php b/exam/api/Login/Login.php index 0fbcca6..70e979b 100644 --- a/exam/api/Login/Login.php +++ b/exam/api/Login/Login.php @@ -10,7 +10,7 @@ use Khofmann\Models\User\User; class Login extends Api { - public function post() + public function post(): void { $email = Input::post("email"); if (empty($email)) throw new Exception("Missing email", 400); @@ -18,7 +18,7 @@ class Login extends Api if (empty($password)) throw new Exception("Missing password", 400); try { - return Response::json(User::logIn($email, $password)); + Response::json(User::logIn($email, $password)); } catch (Exception $err) { switch ($err->getMessage()) { case "Failed": diff --git a/exam/api/Logout/Logout.php b/exam/api/Logout/Logout.php index 1cbdcb5..04f2806 100644 --- a/exam/api/Logout/Logout.php +++ b/exam/api/Logout/Logout.php @@ -9,9 +9,10 @@ use Khofmann\Response\Response; class Logout extends Api { - public function post() + public function post(): void { $token = Request::header("token"); - return Response::json(User::getByToken($token)->logOut()); + + Response::json(User::getByToken($token)->logOut()); } } diff --git a/exam/api/Register/Register.php b/exam/api/Register/Register.php index bc38868..a45ccc5 100644 --- a/exam/api/Register/Register.php +++ b/exam/api/Register/Register.php @@ -10,7 +10,7 @@ use Khofmann\Models\User\User; class Register extends Api { - public function post() + public function post(): void { $username = Input::post("username"); if (empty($username)) throw new Exception("Missing username", 400); @@ -20,7 +20,7 @@ class Register extends Api if (empty($password)) throw new Exception("Missing password", 400); try { - return Response::json(User::create($username, $email, $password)); + Response::json(User::create($username, $email, $password)); } catch (Exception $err) { switch ($err->getMessage()) { case "Duplicate": diff --git a/exam/api/User/User.php b/exam/api/User/User.php index 4683d8e..88c5b61 100644 --- a/exam/api/User/User.php +++ b/exam/api/User/User.php @@ -11,10 +11,10 @@ use Khofmann\Request\Request; class User extends Api { - public function get($id) + public function get($id): void { try { - return Response::json(MUser::getByID($id)); + Response::json(MUser::getByID($id)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": @@ -25,14 +25,14 @@ class User extends Api } } - public function patch($id) + public function patch($id): void { $username = Input::patch("username"); $password = Input::patch("password"); $image = Input::file("image"); try { - return Response::json(MUser::getByID($id)->update($username, $password, $image)); + Response::json(MUser::getByID($id)->update($username, $password, $image)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": @@ -49,7 +49,7 @@ class User extends Api } } - public function patchSelf() + public function patchSelf(): void { $token = Request::header("token"); $username = Input::patch("username"); @@ -57,7 +57,7 @@ class User extends Api $image = Input::file("image"); try { - return Response::json(MUser::getByToken($token)->update($username, $password, $image)); + Response::json(MUser::getByToken($token)->update($username, $password, $image)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": @@ -74,10 +74,10 @@ class User extends Api } } - public function delete($id) + public function delete($id): void { try { - return Response::json(MUser::getByID($id)->delete()); + Response::json(MUser::getByID($id)->delete()); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": diff --git a/exam/classes/Database/Database.php b/exam/classes/Database/Database.php index c898014..c531687 100644 --- a/exam/classes/Database/Database.php +++ b/exam/classes/Database/Database.php @@ -8,7 +8,7 @@ class Database extends PDO { private static array $instances = []; - protected function __construct($dsn, $username = null, $password = null, array $options = null) + protected function __construct(string $dsn, string $username = null, string $password = null, array $options = null) { parent::__construct($dsn, $username, $password, $options); } diff --git a/exam/classes/GUID/GUID.php b/exam/classes/GUID/GUID.php index e14f503..c1df4af 100644 --- a/exam/classes/GUID/GUID.php +++ b/exam/classes/GUID/GUID.php @@ -4,7 +4,7 @@ namespace Khofmann\GUID; class GUID { - public static function v4($data = null) + public static function v4($data = null): string { // Generate 16 bytes (128 bits) of random data or use the data passed into the function. $data = $data ?? random_bytes(16); diff --git a/exam/classes/Input/Input.php b/exam/classes/Input/Input.php index 8ccec03..80aaebf 100644 --- a/exam/classes/Input/Input.php +++ b/exam/classes/Input/Input.php @@ -6,24 +6,22 @@ use Khofmann\Request\Request; class Input { - - - public static function post($index, $defaultValue = null) + public static function post(string $index, $defaultValue = null) { return Request::request()->getInputHandler()->post($index, $defaultValue); } - public static function patch($index, $defaultValue = null) + public static function patch(string $index, $defaultValue = null) { return Request::request()->getInputHandler()->post($index, $defaultValue); } - public static function get($index, $defaultValue = null) + public static function get(string $index, $defaultValue = null) { return Request::request()->getInputHandler()->get($index, $defaultValue); } - public static function file($index, $defaultValue = null) + public static function file(string $index, $defaultValue = null) { return Request::request()->getInputHandler()->file($index, $defaultValue); } diff --git a/exam/classes/Models/User/User.php b/exam/classes/Models/User/User.php index f7b0ec2..45f386b 100644 --- a/exam/classes/Models/User/User.php +++ b/exam/classes/Models/User/User.php @@ -155,7 +155,7 @@ class User implements JsonSerializable } } - public static function create(string $username, string $email, string $password) + public static function create(string $username, string $email, string $password): bool { $db = Database::getInstance(); $guid = GUID::v4(); @@ -186,6 +186,10 @@ class User implements JsonSerializable throw $err; } } + + public static function confirm(string $confirmCode): bool + { + } /* * Members */ @@ -198,7 +202,7 @@ class User implements JsonSerializable return $stmt->execute(); } - public function update(?string $username, ?string $password, $image = null) + public function update(?string $username, ?string $password, $image = null): bool { $db = Database::getInstance(); @@ -233,7 +237,7 @@ class User implements JsonSerializable return true; } - public function delete() + public function delete(): bool { $db = Database::getInstance(); $stmt = $db->prepare("DELETE FROM egb_benutzer WHERE id = :ID"); diff --git a/exam/classes/Request/Request.php b/exam/classes/Request/Request.php index 048e72e..3b5e3ee 100644 --- a/exam/classes/Request/Request.php +++ b/exam/classes/Request/Request.php @@ -12,7 +12,7 @@ class Request return SimpleRouter::request(); } - public static function header($name, $defaultValue = null, $tryParse = true) + public static function header(string $name, $defaultValue = null, bool $tryParse = true): ?string { return request()->getHeader($name, $defaultValue, $tryParse); } diff --git a/exam/classes/Response/Response.php b/exam/classes/Response/Response.php index 0457c96..bc66a6a 100644 --- a/exam/classes/Response/Response.php +++ b/exam/classes/Response/Response.php @@ -12,13 +12,13 @@ class Response return SimpleRouter::response(); } - public static function json($value, int $options = 0, int $dept = 512) + public static function json($value, int $options = 0, int $dept = 512): void { if (is_bool($value)) { Response::response()->header('Content-Type: application/json; charset=utf-8'); echo json_encode($value, $options, $dept); exit(0); } - return SimpleRouter::response()->json($value, $options, $dept); + SimpleRouter::response()->json($value, $options, $dept); } } diff --git a/exam/config/Config.php b/exam/config/Config.php index 4581b4d..768abda 100644 --- a/exam/config/Config.php +++ b/exam/config/Config.php @@ -34,22 +34,22 @@ class Config return self::$instances[$cls]; } - public static function getBasePath() + public static function getBasePath(): string { return Config::getInstance()->app["basePath"]; } - public static function getBaseFSPath() + public static function getBaseFSPath(): string { return Config::getInstance()->app["baseFSPath"]; } - public static function getStoragePath() + public static function getStoragePath(): string { return Config::getInstance()->app["storagePath"]; } - public static function getDatabase() + public static function getDatabase(): array { return Config::getInstance()->database; } diff --git a/exam/utils/helpers.php b/exam/utils/helpers.php index 019d138..67e226f 100644 --- a/exam/utils/helpers.php +++ b/exam/utils/helpers.php @@ -38,17 +38,3 @@ function redirect(string $url, ?int $code = null): void response()->redirect($url); } - -/** - * Get current csrf-token - * @return string|null - */ -function csrf_token(): ?string -{ - $baseVerifier = Router::router()->getCsrfVerifier(); - if ($baseVerifier !== null) { - return $baseVerifier->getTokenProvider()->getToken(); - } - - return null; -}