You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
762 B
25 lines
762 B
<?php
|
|
|
|
namespace App\Router\Middleware;
|
|
use App\Router\Session;
|
|
use Network\IAuthService;
|
|
use Shared\Log;
|
|
use App\Router\Request\IRequest;
|
|
use App\Router\Response\RedirectResponse;
|
|
class AuthMiddleware extends Middleware {
|
|
|
|
private IAuthService $auth;
|
|
public function __construct(IAuthService $auth) {
|
|
$this->auth = $auth;
|
|
}
|
|
public function handle(IRequest $request, callable $next) {
|
|
$excludedUrls = ['/login', '/register','/forgetPassword', '/', '/mock'];
|
|
if ($this->auth->getCurrentUser() === null && !in_array($request->getRequestUri(), $excludedUrls)) {
|
|
$resp = new RedirectResponse("/login");
|
|
$resp->send();
|
|
exit;
|
|
}
|
|
|
|
return parent::handle($request, $next);
|
|
}
|
|
} |