46 lines
1.2 KiB
PHP
Executable File
46 lines
1.2 KiB
PHP
Executable File
<?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
|
|
}
|
|
}
|
|
}
|
|
}
|