From 76f3e4d303bfcc737b532831ae009af9390ff584 Mon Sep 17 00:00:00 2001 From: Michael Darko Date: Sun, 13 Feb 2022 17:42:24 +0000 Subject: [PATCH 1/3] added db_table config --- src/Auth/Core.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Auth/Core.php b/src/Auth/Core.php index ef65478..22870ed 100644 --- a/src/Auth/Core.php +++ b/src/Auth/Core.php @@ -24,26 +24,27 @@ class Core * Auth Settings */ protected static $settings = [ - "AUTH_NO_PASS" => false, - "USE_TIMESTAMPS" => true, - "PASSWORD_ENCODE" => null, - "PASSWORD_VERIFY" => null, - "PASSWORD_KEY" => "password", - "HIDE_ID" => true, - "ID_KEY" => "id", - "USE_UUID" => false, - "HIDE_PASSWORD" => true, - "LOGIN_PARAMS_ERROR" => "Incorrect credentials!", - "LOGIN_PASSWORD_ERROR" => "Password is incorrect!", - "USE_SESSION" => false, - "SESSION_ON_REGISTER" => false, - "GUARD_LOGIN" => "/auth/login", - "GUARD_REGISTER" => "/auth/register", - "GUARD_HOME" => "/home", - "GUARD_LOGOUT" => "/auth/logout", - "SAVE_SESSION_JWT" => false, - "TOKEN_LIFETIME" => null, - "TOKEN_SECRET" => "@_leaf$0Secret!" + 'DB_TABLE' => 'users', + 'AUTH_NO_PASS' => false, + 'USE_TIMESTAMPS' => true, + 'PASSWORD_ENCODE' => null, + 'PASSWORD_VERIFY' => null, + 'PASSWORD_KEY' => 'password', + 'HIDE_ID' => true, + 'ID_KEY' => 'id', + 'USE_UUID' => false, + 'HIDE_PASSWORD' => true, + 'LOGIN_PARAMS_ERROR' => 'Incorrect credentials!', + 'LOGIN_PASSWORD_ERROR' => 'Password is incorrect!', + 'USE_SESSION' => false, + 'SESSION_ON_REGISTER' => false, + 'GUARD_LOGIN' => '/auth/login', + 'GUARD_REGISTER' => '/auth/register', + 'GUARD_HOME' => '/home', + 'GUARD_LOGOUT' => '/auth/logout', + 'SAVE_SESSION_JWT' => false, + 'TOKEN_LIFETIME' => null, + 'TOKEN_SECRET' => '@_leaf$0Secret!', ]; /** From 0f92dad3ebb0b38e276ad7739e1870e3021a43f7 Mon Sep 17 00:00:00 2001 From: Michael Darko Date: Sun, 13 Feb 2022 17:53:31 +0000 Subject: [PATCH 2/3] :fire: switched to table config --- src/Auth.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 71e73db..f977048 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -20,16 +20,15 @@ class Auth extends Core /** * Simple user login * - * @param string table: Table to look for users * @param array $credentials User credentials * * @return array|null null or all user info + tokens + session data */ - public static function login( - string $table, - array $credentials - ) { + public static function login(array $credentials) { static::leafDbConnect(); + + $table = static::$settings['DB_TABLE']; + if (static::config('USE_SESSION')) { static::useSession(); } @@ -116,19 +115,18 @@ public static function login( /** * Simple user registration * - * @param string $table Table to store user in * @param array $credentials Information for new user * @param array $uniques Parameters which should be unique * * @return array null or all user info + tokens + session data */ public static function register( - string $table, array $credentials, array $uniques = [] ) { static::leafDbConnect(); - + + $table = static::$settings['DB_TABLE']; $passKey = static::$settings['PASSWORD_KEY']; if (!isset($credentials[$passKey])) { @@ -226,16 +224,17 @@ public static function register( /** * Simple user update * - * @param string $table Table to store user in * @param array $credentials New information for user - * @param array $where Information to find user by * @param array $uniques Parameters which should be unique * * @return array all user info + tokens + session data */ - public static function update(string $table, array $credentials, array $uniques = []) + public static function update(array $credentials, array $uniques = []) { static::leafDbConnect(); + + $table = static::$settings['DB_TABLE']; + if (static::config('USE_SESSION')) { static::useSession(); } @@ -442,11 +441,12 @@ public static function id() /** * Get the current user data from token * - * @param string $table The table to look for user * @param array $hidden Fields to hide from user array */ - public static function user(string $table = 'users', array $hidden = []) + public static function user(array $hidden = []) { + $table = static::$settings['DB_TABLE']; + if (!static::id()) { if (static::config('USE_SESSION')) { return static::$session->get('AUTH_USER'); @@ -481,7 +481,7 @@ public static function logout(?string $location = null) if (is_string($location)) { $route = static::config($location) ?? $location; - return \Leaf\Http\Response::redirect($route); + exit(\Leaf\Http\Response::redirect($route)); } } From 211e28e179f63ed09080547a6a1fef03f9c72286 Mon Sep 17 00:00:00 2001 From: Michael Darko Date: Sun, 13 Feb 2022 18:19:08 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactored=20auth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Auth.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index f977048..7bed195 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -120,12 +120,9 @@ 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']; $passKey = static::$settings['PASSWORD_KEY'];