From 5e42aac78f1b51fc1c285228eb79cb4f98f96306 Mon Sep 17 00:00:00 2001 From: Michael Darko Date: Thu, 17 Feb 2022 22:07:07 +0000 Subject: [PATCH 1/2] :bug: fixed connection bug --- src/Auth/Core.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Auth/Core.php b/src/Auth/Core.php index 8deabaf..8335ee1 100644 --- a/src/Auth/Core.php +++ b/src/Auth/Core.php @@ -59,7 +59,7 @@ class Core /** * Connect leaf auth to the database - * + * * @param string|array $host Host Name or full config * @param string $dbname Database name * @param string $user Database username @@ -77,16 +77,17 @@ public static function connect( ) { $db = new \Leaf\Db(); $db->connect($host, $dbname, $user, $password, $dbtype, $pdoOptions); + static::$db = $db; } /** * Connect to database using environment variables - * + * * @param array $pdoOptions Options for PDO connection */ - public function autoConnect(array $pdoOptions = []) + public static function autoConnect(array $pdoOptions = []) { - $this->connect( + static::connect( getenv('DB_HOST'), getenv('DB_DATABASE'), getenv('DB_USERNAME'), @@ -98,7 +99,7 @@ public function autoConnect(array $pdoOptions = []) /** * Pass in db connetion instance directly - * + * * @param \PDO $connection A connection instance of your db */ public static function dbConnection(\PDO $connection) @@ -126,7 +127,7 @@ protected static function leafDbConnect() /** * Set auth config - * + * * @param string|array $config The auth config key or array of config * @param mixed $value The value if $config is a string */ From e7f261d740a4b19b60d52bf677e733707660b3a0 Mon Sep 17 00:00:00 2001 From: Michael Darko Date: Thu, 17 Feb 2022 22:09:21 +0000 Subject: [PATCH 2/2] :bug: fixed redirect bug --- src/Auth.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 7bed195..6dcc016 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -24,7 +24,8 @@ class Auth extends Core * * @return array|null null or all user info + tokens + session data */ - public static function login(array $credentials) { + public static function login(array $credentials) + { static::leafDbConnect(); $table = static::$settings['DB_TABLE']; @@ -120,7 +121,8 @@ public static function login(array $credentials) { * * @return array null or all user info + tokens + session data */ - public static function register(array $credentials, array $uniques = []) { + public static function register(array $credentials, array $uniques = []) + { static::leafDbConnect(); $table = static::$settings['DB_TABLE']; @@ -353,7 +355,7 @@ public static function update(array $credentials, array $uniques = []) /** * Validation for parameters - * + * * @param array $rules Rules for parameter validation */ public function validate(array $rules): bool @@ -467,7 +469,7 @@ public static function user(array $hidden = []) /** * End a session - * + * * @param string $location A route to redirect to after logout */ public static function logout(?string $location = null) @@ -478,7 +480,8 @@ public static function logout(?string $location = null) if (is_string($location)) { $route = static::config($location) ?? $location; - exit(\Leaf\Http\Response::redirect($route)); + \Leaf\Http\Headers::status(302); + exit(header("location: $route")); } } @@ -494,7 +497,7 @@ public static function lastActive() /** * Refresh session - * + * * @param bool $clearData Remove existing session data */ public static function refresh(bool $clearData = true) @@ -512,7 +515,7 @@ public static function refresh(bool $clearData = true) /** * Define/Return session middleware - * + * * @param string $name The name of the middleware to set/get * @param callable|null $handler The handler for the middleware */