Skip to content

Commit

Permalink
Поправил заголовки закрытия сайта и ip бана
Browse files Browse the repository at this point in the history
  • Loading branch information
visavi committed Jul 4, 2021
1 parent cd1a5be commit e8409e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
18 changes: 8 additions & 10 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\Response;

class HomeController extends Controller
{
Expand All @@ -27,17 +28,15 @@ public function index(): View
/**
* Закрытие сайта
*
* @return View|RedirectResponse
* @return Response
*/
public function closed()
{
if (setting('closedsite') !== 2) {
return redirect('/');
}

header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');

return view('pages/closed');
return response()->view('pages/closed', [], 503);
}

/**
Expand All @@ -55,9 +54,9 @@ public function search(): View
*
* @param Request $request
*
* @return View|RedirectResponse
* @return Response
*/
public function ipban(Request $request)
public function ipban(Request $request): Response
{
$ban = Ban::query()
->where('ip', getIp())
Expand All @@ -69,7 +68,8 @@ public function ipban(Request $request)
return redirect('/');
}

if (! $ban->user_id
if (
! $ban->user_id
&& $ban->created_at < strtotime('-1 minute', SITETIME)
&& $request->isMethod('post')
&& captchaVerify()
Expand All @@ -82,9 +82,7 @@ public function ipban(Request $request)
return redirect('/');
}

header($_SERVER['SERVER_PROTOCOL'] . ' 429 Too Many Requests');

return view('pages/ipban', compact('ban'));
return response()->view('pages/ipban', compact('ban'), 429);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Middleware/CheckAccessSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ public function handle(Request $request, Closure $next)
if (
setting('closedsite') === 1 &&
! getUser() &&
! $request->is('register', 'login', 'recovery', 'captcha')
! $request->is('login', 'register', 'recovery', 'captcha')
) {
setFlash('danger', __('main.not_authorized'));

return redirect('login');
}

// Сайт закрыт для всех
if (
setting('closedsite') === 2 &&
! isAdmin() &&
! $request->is('login', 'closed')
! $request->is('login', 'captcha', 'closed')
) {
return redirect('closed');
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/errors/403.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="col-12 text-center">
<h1>{{ __('errors.error') }} 403!</h1>

<div class="lead">{{ __('errors.forbidden') }}</div>
<div class="lead">{{ $exception->getMessage() ?: __('errors.forbidden') }}</div>

<div class="my-3">
<a class="btn btn-primary" href="{{ url()->previous() }}"><i class="fa fa-arrow-circle-left"></i> {{ __('errors.return') }}</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/errors/404.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="col-12 text-center">
<h1>{{ __('errors.error') }} 404!</h1>

<div class="lead">{{ __('errors.not_found') }}</div>
<div class="lead">{{ $exception->getMessage() ?: __('errors.not_found') }}</div>

<div class="my-3">
<a class="btn btn-primary" href="{{ url()->previous() }}"><i class="fa fa-arrow-circle-left"></i> {{ __('errors.return') }}</a>
Expand Down

0 comments on commit e8409e4

Please sign in to comment.