Skip to content

Commit

Permalink
🔖 prepping for v2.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Sep 19, 2021
1 parent 7c6dcda commit 6e3e15a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 56 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
<!-- markdownlint-disable no-duplicate-header -->
# 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
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- markdownlint-disable no-inline-html -->
<p align="center">
<br><br>
<img src="https://leaf-docs.netlify.app/images/logo.png" height="100"/>
<h1 align="center">Leaf PHP Framework</h1>
<br><br>
<br><br>
<img src="https://leaf-docs.netlify.app/images/logo.png" height="100"/>
<h1 align="center">Leaf PHP Framework</h1>
<br><br>
</p>

# Leaf PHP
Expand Down Expand Up @@ -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 ❤️

<a href="https://github.com/leafsphp/fetch/graphs/contributors" target="_blank"><img src="https://opencollective.com/leafphp/contributors.svg?width=890" /></a>

## View Leaf's docs [here](https://leafphp.netlify.app/#/)

Built with ❤ by [**Mychi Darko**](https://mychi.netlify.app)
47 changes: 29 additions & 18 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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])) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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])) {
Expand All @@ -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);
Expand Down Expand Up @@ -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])) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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());
Expand Down
7 changes: 6 additions & 1 deletion src/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 0 additions & 26 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 1 addition & 7 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down

0 comments on commit 6e3e15a

Please sign in to comment.