Skip to content

Commit

Permalink
πŸ”€ Merge pull request #6 from mychidarko/main
Browse files Browse the repository at this point in the history
Critical Fixes
  • Loading branch information
mychidarko committed Feb 17, 2022
2 parents 35db2b4 + e7f261d commit a33ced3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/Auth.php
Expand Up @@ -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'];
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"));
}
}

Expand All @@ -494,7 +497,7 @@ public static function lastActive()

/**
* Refresh session
*
*
* @param bool $clearData Remove existing session data
*/
public static function refresh(bool $clearData = true)
Expand All @@ -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
*/
Expand Down
13 changes: 7 additions & 6 deletions src/Auth/Core.php
Expand Up @@ -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
Expand All @@ -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'),
Expand All @@ -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)
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit a33ced3

Please sign in to comment.