This commit is contained in:
zuevav
2026-04-30 15:14:09 +03:00
parent 08fe53fa5c
commit e5a88665cd
25 changed files with 13697 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
<?php
/**
* Страница первоначальной настройки - создание администратора
*/
session_start();
require_once __DIR__ . '/classes/Auth.php';
$auth = new Auth();
// If users already exist, redirect to login
if ($auth->hasUsers()) {
header('Location: login.php');
exit;
}
$error = '';
$success = false;
// Handle setup form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$confirmPassword = $_POST['confirm_password'] ?? '';
// Validation
if (empty($username)) {
$error = 'Имя пользователя обязательно';
} elseif (strlen($username) < 3) {
$error = 'Имя пользователя должно быть не менее 3 символов';
} elseif (strlen($password) < 8) {
$error = 'Пароль должен быть не менее 8 символов';
} elseif ($password !== $confirmPassword) {
$error = 'Пароли не совпадают';
} else {
// Create user
if ($auth->createUser($username, $password)) {
$success = true;
} else {
$error = 'Не удалось создать пользователя';
}
}
}
// CSRF token
$csrfToken = bin2hex(random_bytes(32));
$_SESSION['csrf_token'] = $csrfToken;
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Настройка - VH Posting System</title>
<link rel="stylesheet" href="css/style.css">
<script>
// Apply saved theme immediately
(function() {
const theme = localStorage.getItem('theme') || 'light';
if (theme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
})();
</script>
</head>
<body class="login-page">
<div class="login-container">
<div class="login-box">
<h1>VH Posting System</h1>
<h2>Первоначальная настройка</h2>
<?php if ($success): ?>
<div class="alert alert-success">
Администратор успешно создан!
<br><br>
<a href="login.php" class="btn btn-primary">Перейти ко входу</a>
</div>
<?php else: ?>
<p class="help-text">Создайте учётную запись администратора</p>
<?php if ($error): ?>
<div class="alert alert-error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST" action="setup.php">
<input type="hidden" name="csrf_token" value="<?= $csrfToken ?>">
<div class="form-group">
<label for="username">Имя пользователя:</label>
<input type="text" id="username" name="username" required autofocus
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"
minlength="3">
</div>
<div class="form-group">
<label for="password">Пароль:</label>
<input type="password" id="password" name="password" required minlength="8">
<span class="hint">Минимум 8 символов</span>
</div>
<div class="form-group">
<label for="confirm_password">Подтвердите пароль:</label>
<input type="password" id="confirm_password" name="confirm_password" required>
</div>
<button type="submit" class="btn btn-primary btn-large btn-block">Создать администратора</button>
</form>
<?php endif; ?>
</div>
</div>
</body>
</html>