шаг 5 завершен
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Core\Auth;
|
||||
use App\Repositories\AdminRepository;
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/app/bootstrap.php';
|
||||
|
||||
$repository = new AdminRepository();
|
||||
$needsSetup = $repository->activeCount() === 0;
|
||||
|
||||
if ($needsSetup) {
|
||||
header('Location: /admin/setup.php?token=' . rawurlencode((string) app_env('INSTALL_TOKEN', '')));
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = null;
|
||||
$next = admin_safe_next((string) ($_GET['next'] ?? '/admin/'));
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$next = admin_safe_next((string) ($_POST['next'] ?? '/admin/'));
|
||||
|
||||
if (Auth::attempt((string) ($_POST['email'] ?? ''), (string) ($_POST['password'] ?? ''))) {
|
||||
header('Location: ' . ($next !== '' ? $next : '/admin/'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = 'Неверный email или пароль.';
|
||||
}
|
||||
|
||||
view('admin/login', [
|
||||
'title' => 'Вход в админку - Рыбсток',
|
||||
'breadcrumbs' => [
|
||||
['title' => 'Главная', 'url' => '/'],
|
||||
['title' => 'Админка', 'url' => '/admin/'],
|
||||
['title' => 'Вход'],
|
||||
],
|
||||
'error' => $error,
|
||||
'next' => $next,
|
||||
]);
|
||||
|
||||
function admin_safe_next(string $next): string
|
||||
{
|
||||
if ($next === '' || !str_starts_with($next, '/') || str_starts_with($next, '//')) {
|
||||
return '/admin/';
|
||||
}
|
||||
|
||||
return $next;
|
||||
}
|
||||
Reference in New Issue
Block a user