Skip to content

Commit

Permalink
πŸ”€ Merge pull request #4 from mychidarko/main
Browse files Browse the repository at this point in the history
Add DB_TABLE config
  • Loading branch information
mychidarko authored Feb 13, 2022
2 parents 3ba37ad + 211e28e commit 90ce822
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
31 changes: 14 additions & 17 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -116,19 +115,15 @@ 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 = []
) {
public static function register(array $credentials, array $uniques = []) {
static::leafDbConnect();

$table = static::$settings['DB_TABLE'];
$passKey = static::$settings['PASSWORD_KEY'];

if (!isset($credentials[$passKey])) {
Expand Down Expand Up @@ -226,16 +221,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();
}
Expand Down Expand Up @@ -442,11 +438,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');
Expand Down Expand Up @@ -481,7 +478,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));
}
}

Expand Down
41 changes: 21 additions & 20 deletions src/Auth/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
];

/**
Expand Down

0 comments on commit 90ce822

Please sign in to comment.