-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/authentication' into develop
- Loading branch information
Showing
9 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace AGerault\Framework\Authentication; | ||
|
||
use AGerault\Framework\Contracts\Authentication\AuthenticatableInterface; | ||
use AGerault\Framework\Contracts\Authentication\AuthenticatorInterface; | ||
|
||
class Authenticator implements AuthenticatorInterface | ||
{ | ||
|
||
public function check(AuthenticatableInterface $authenticatable, array $credentials): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function attempt(AuthenticatableInterface $authenticatable, array $credentials): ?AuthenticatableInterface | ||
{ | ||
return $credentials['login'] === $authenticatable->login() | ||
&& password_verify($credentials['password'], $authenticatable->password()) ? $authenticatable : null; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/AGerault/Contracts/Authentication/AuthenticatableInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace AGerault\Framework\Contracts\Authentication; | ||
|
||
interface AuthenticatableInterface | ||
{ | ||
/** | ||
* A unique identifier to fetch a user | ||
*/ | ||
public function key(): int|string; | ||
|
||
public function login(): string; | ||
|
||
public function password(): string; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/AGerault/Contracts/Authentication/AuthenticatableProviderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace AGerault\Framework\Contracts\Authentication; | ||
|
||
interface AuthenticatableProviderInterface | ||
{ | ||
public function fetch(string|int $key): AuthenticatableInterface; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/AGerault/Contracts/Authentication/AuthenticatorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace AGerault\Framework\Contracts\Authentication; | ||
|
||
interface AuthenticatorInterface | ||
{ | ||
/** | ||
* Check whether the credentials match for a given user | ||
*/ | ||
public function check(AuthenticatableInterface $authenticatable, array $credentials): bool; | ||
|
||
/** | ||
* Try to log in a given user based on credentials | ||
*/ | ||
public function attempt(AuthenticatableInterface $authenticatable, array $credentials): ?AuthenticatableInterface; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/AGerault/Contracts/Authentication/Exceptions/AuthenticatableNotFoundException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace AGerault\Framework\Contracts\Authentication\Exceptions; | ||
|
||
use Exception; | ||
|
||
class AuthenticatableNotFoundException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace AGerault\Framework\Session; | ||
|
||
use AGerault\Framework\Contracts\Session\SessionInterface; | ||
|
||
class Session implements SessionInterface | ||
{ | ||
public function __construct() | ||
{ | ||
session_start(); | ||
} | ||
|
||
public function has(string $key): bool | ||
{ | ||
return isset($_SESSION[$key]); | ||
} | ||
|
||
public function get(string $key): mixed | ||
{ | ||
return $_SESSION[$key] ?? null; | ||
} | ||
|
||
public function put(string $key, mixed $payload): void | ||
{ | ||
$_SESSION[$key] = $payload; | ||
} | ||
|
||
public function clear(): void | ||
{ | ||
session_destroy(); | ||
} | ||
|
||
public function forget(string $key): void | ||
{ | ||
unset($_SESSION[$key]); | ||
} | ||
} |