From 6e3e15a12ebf15b8a79bd365b3a101a40b1bb763 Mon Sep 17 00:00:00 2001 From: Mychi Date: Sun, 19 Sep 2021 05:08:46 +0000 Subject: [PATCH] :bookmark: prepping for v2.6 release --- CHANGELOG.md | 17 +++++++++++++++++ README.md | 14 ++++++++++---- src/Auth.php | 47 ++++++++++++++++++++++++++++------------------ src/Flash.php | 7 ++++++- src/Middleware.php | 26 ------------------------- src/Router.php | 8 +------- 6 files changed, 63 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b741c63..91d4b78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,23 @@ # Changelog +## v2.6.0 - ⚰️ The Goodbye Flower - 20th September, 2021 + +## Added + +- Added UUID support to Leaf Auth +- Added support for custom id keys in Leaf Auth + +### Fixed + +- Fixed Request::getUrl +- Fixed issue [#53](https://github.com/leafsphp/leaf/issues/53) +- Fixed Database + +### Removed + +- Removed Leaf blade component + ## v2.5.1 - 💠 Lilac - 30th May, 2021 ### Fixed diff --git a/README.md b/README.md index 0ede2b0..16d6473 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@

-

- -

Leaf PHP Framework

-

+

+ +

Leaf PHP Framework

+

# Leaf PHP @@ -91,6 +91,12 @@ Skeleton is the latest package included in the Leaf family. Skeleton is a custom Of course, with this core package, you can build your app in any way that you wish to as Leaf contains all the required functionality to do so +## Our contributors + +And to all our contributors, we love you all ❤️ + + + ## View Leaf's docs [here](https://leafphp.netlify.app/#/) Built with ❤ by [**Mychi Darko**](https://mychi.netlify.app) diff --git a/src/Auth.php b/src/Auth.php index 3411b26..32bbe2a 100755 --- a/src/Auth.php +++ b/src/Auth.php @@ -45,6 +45,8 @@ class Auth * Auth Settings */ protected static $settings = [ + "ID_KEY" => "id", + "USE_UUID" => false, "USE_TIMESTAMPS" => true, "PASSWORD_ENCODE" => null, "PASSWORD_VERIFY" => null, @@ -313,6 +315,7 @@ public static function login(string $table, array $credentials, array $validate } $user = static::$db->select($table)->where($credentials)->validate($validate)->fetchAssoc(); + if (!$user) { static::$errorsArray["auth"] = static::$settings["LOGIN_PARAMS_ERROR"]; return null; @@ -335,14 +338,18 @@ public static function login(string $table, array $credentials, array $validate return null; } - $token = Authentication::generateSimpleToken($user["id"], static::$secretKey, static::$lifeTime); + $token = Authentication::generateSimpleToken( + $user[static::$settings["ID_KEY"]], + static::$secretKey, + static::$lifeTime + ); - if (isset($user["id"])) { - $userId = $user["id"]; + if (isset($user[static::$settings["ID_KEY"]])) { + $userId = $user[static::$settings["ID_KEY"]]; } if (static::$settings["HIDE_ID"]) { - unset($user["id"]); + unset($user[static::$settings["ID_KEY"]]); } if (static::$settings["HIDE_PASSWORD"] && (isset($user[$passKey]) || !$user[$passKey])) { @@ -356,7 +363,7 @@ public static function login(string $table, array $credentials, array $validate if (static::config("USE_SESSION")) { if (isset($userId)) { - $user["id"] = $userId; + $user[static::$settings["ID_KEY"]] = $userId; } static::saveToSession("AUTH_USER", $user); @@ -405,6 +412,10 @@ public static function register(string $table, array $credentials, array $unique $credentials["updated_at"] = $now; } + if (static::$settings["USE_UUID"] !== false) { + $credentials[static::$settings["ID_KEY"]] = static::$settings["USE_UUID"]; + } + try { $query = static::$db->insert($table)->params($credentials)->unique($uniques)->validate($validate)->execute(); } catch (\Throwable $th) { @@ -424,14 +435,14 @@ public static function register(string $table, array $credentials, array $unique return null; } - $token = Authentication::generateSimpleToken($user["id"], static::$secretKey, static::$lifeTime); + $token = Authentication::generateSimpleToken($user[static::$settings["ID_KEY"]], static::$secretKey, static::$lifeTime); - if (isset($user["id"])) { - $userId = $user["id"]; + if (isset($user[static::$settings["ID_KEY"]])) { + $userId = $user[static::$settings["ID_KEY"]]; } if (static::$settings["HIDE_ID"]) { - unset($user["id"]); + unset($user[static::$settings["ID_KEY"]]); } if (static::$settings["HIDE_PASSWORD"] && (isset($user[$passKey]) || !$user[$passKey])) { @@ -446,7 +457,7 @@ public static function register(string $table, array $credentials, array $unique if (static::config("USE_SESSION")) { if (static::config("SESSION_ON_REGISTER")) { if (isset($userId)) { - $user["id"] = $userId; + $user[static::$settings["ID_KEY"]] = $userId; } static::saveToSession("AUTH_USER", $user); @@ -538,14 +549,14 @@ public static function update(string $table, array $credentials, array $where, a return null; } - $token = Authentication::generateSimpleToken($user["id"], static::$secretKey, static::$lifeTime); + $token = Authentication::generateSimpleToken($user[static::$settings["ID_KEY"]], static::$secretKey, static::$lifeTime); - if (isset($user["id"])) { - $userId = $user["id"]; + if (isset($user[static::$settings["ID_KEY"]])) { + $userId = $user[static::$settings["ID_KEY"]]; } - if (static::$settings["HIDE_ID"] && isset($user["id"])) { - unset($user["id"]); + if (static::$settings["HIDE_ID"] && isset($user[static::$settings["ID_KEY"]])) { + unset($user[static::$settings["ID_KEY"]]); } if (static::$settings["HIDE_PASSWORD"] && (isset($user[$passKey]) || !$user[$passKey])) { @@ -559,7 +570,7 @@ public static function update(string $table, array $credentials, array $where, a if (static::config("USE_SESSION")) { if (isset($userId)) { - $user["id"] = $userId; + $user[static::$settings["ID_KEY"]] = $userId; } static::saveToSession("AUTH_USER", $user); @@ -638,7 +649,7 @@ public static function user($table = "users", $hidden = []) return null; } - $user = static::$db->select($table)->where("id", static::id())->fetchAssoc(); + $user = static::$db->select($table)->where(static::$settings["ID_KEY"], static::id())->fetchAssoc(); if (count($hidden) > 0) { foreach ($hidden as $item) { @@ -657,7 +668,7 @@ public static function user($table = "users", $hidden = []) public static function id() { if (static::config("USE_SESSION")) { - return static::$session->get("AUTH_USER")["id"] ?? null; + return static::$session->get("AUTH_USER")[static::$settings["ID_KEY"]] ?? null; } $payload = static::validateToken(static::getSecretKey()); diff --git a/src/Flash.php b/src/Flash.php index bc37744..70c3ab5 100644 --- a/src/Flash.php +++ b/src/Flash.php @@ -83,7 +83,12 @@ private static function get(string $key = null) $key = static::$config["default"]; } - $item = Http\Session::get(static::$config["key"], false)[$key]; + $item = null; + $items = Http\Session::get(static::$config["key"], false); + + if (isset($items[$key])) { + $item = $items[$key]; + } if ($key) { static::unset($key); diff --git a/src/Middleware.php b/src/Middleware.php index 1b06717..5726ef8 100755 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -21,32 +21,6 @@ abstract class Middleware */ protected $next; - /** - * Set application - * - * This method injects the primary Leaf application instance into - * this middleware. - * - * @param \Leaf\App $application - */ - final public function setApplication($application) - { - $this->app = $application; - } - - /** - * Get application - * - * This method retrieves the application previously injected - * into this middleware. - * - * @return \Leaf\App - */ - final public function getApplication() - { - return $this->app; - } - /** * Set next middleware * diff --git a/src/Router.php b/src/Router.php index dc184c5..d32ef0c 100644 --- a/src/Router.php +++ b/src/Router.php @@ -465,19 +465,13 @@ public static function before(string $methods, $path, callable $handler) * * @param \Leaf\Middleware */ - public static function add(\Leaf\Middleware $newMiddleware) + public static function add($newMiddleware) { if (in_array($newMiddleware, static::$middleware)) { $middleware_class = get_class($newMiddleware); throw new \RuntimeException("Circular Middleware setup detected. Tried to queue the same Middleware instance ({$middleware_class}) twice."); } - if (Config::get("app")["instance"]) { - $newMiddleware->setApplication( - Config::get("app")["instance"] - ); - } - if (!empty(static::$middleware)) { $newMiddleware->setNextMiddleware(static::$middleware[0]); }