First Commit
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Auth\Providers;
|
||||
|
||||
use Kernel\Application;
|
||||
use Kernel\View;
|
||||
use Modules\Auth\Models\User;
|
||||
use Modules\Auth\Middleware\AuthMiddleware;
|
||||
|
||||
class AuthServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$app = Application::getInstance();
|
||||
|
||||
// Register Middleware
|
||||
$app->addProtectedMiddleware(new AuthMiddleware());
|
||||
|
||||
// Register Public Routes
|
||||
$app->addPublicPath('/login');
|
||||
$app->addPublicPath('/register');
|
||||
$app->addPublicPath('/forgot-password');
|
||||
$app->addPublicPath('/reset-password*'); // Prefix
|
||||
$app->addPublicPath('/verify-email*'); // Prefix
|
||||
|
||||
// Inject Auth Global
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
try {
|
||||
if (class_exists(User::class)) {
|
||||
$user = User::find($_SESSION['user_id']);
|
||||
if ($user) {
|
||||
$view = new View();
|
||||
$view->getEngine()->addGlobal('auth', ['user' => $user]);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user