-
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 pull request #55 from v1p3r75/refactoring
Refactoring
- Loading branch information
Showing
46 changed files
with
832 additions
and
208 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
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,60 @@ | ||
<?php | ||
|
||
namespace Floky\Auth; | ||
use Floky\Collections\Collection; | ||
use Floky\Config\Config; | ||
use Floky\Session\Session; | ||
|
||
class Auth | ||
{ | ||
|
||
const USER_KEY = '_user'; | ||
|
||
public static function login( | ||
string $id, | ||
string $password, | ||
array $options = ['id' => 'email', 'password' => 'password'] | ||
): bool { | ||
|
||
$model = Config::get('auth.model'); | ||
|
||
if (!class_exists($model)) { | ||
|
||
throw new \Exception('Auth model not found : ' . $model); | ||
} | ||
|
||
$model = new $model; | ||
|
||
if ($result = $model->where([$options['id'] => $id])->first()) { | ||
|
||
if (Security::check($password, $result[$options['password']])) { | ||
|
||
unset($result[$options['password']]); | ||
Session::set(self::USER_KEY, new Collection($result)); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static function user() { | ||
|
||
return Session::get(self::USER_KEY) ?? null; | ||
} | ||
|
||
public static function logout(bool $redirect = true, string $redirect_to = '') { | ||
|
||
Session::set(self::USER_KEY, null); | ||
|
||
if ($redirect) { | ||
|
||
$home = $redirect_to == '' ? \App\Providers\AppServiceProvider::HOME : $redirect_to; | ||
|
||
header("Location: $home"); | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
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,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
class {{name}} extends Controller | ||
{ | ||
|
||
public function index() { | ||
|
||
} | ||
|
||
public function show($id) { | ||
|
||
} | ||
|
||
public function create() { | ||
|
||
} | ||
|
||
public function edit($id) { | ||
|
||
} | ||
|
||
public function update() { | ||
|
||
} | ||
|
||
public function delete() { | ||
|
||
} | ||
|
||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Http\Middlewares; | ||
|
||
use Closure; | ||
use Floky\Http\Middlewares\MiddlewareInterface; | ||
use Floky\Http\Requests\Request; | ||
|
||
class {{name}} implements MiddlewareInterface | ||
{ | ||
public function handle(Request $request): Request { | ||
|
||
return $request; | ||
|
||
public function handle(Request $request, Closure $next) | ||
{ | ||
|
||
// handle request | ||
|
||
return $next($request); | ||
|
||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Floky\Events; | ||
|
||
|
||
interface Event | ||
{ | ||
|
||
public function handle(Event $event): void; | ||
} |
Oops, something went wrong.