mirror of
https://git.sr.ht/~iwakuralain/text0Nly
synced 2025-07-27 15:36:11 +00:00
83 lines
3.2 KiB
PHP
83 lines
3.2 KiB
PHP
<?php
|
||
require_once 'config.php';
|
||
require_once 'functions.php';
|
||
|
||
session_start();
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$username = $_POST['username'] ?? '';
|
||
$password = $_POST['password'] ?? '';
|
||
$pgp_key = $_POST['pgp_key'] ?? '';
|
||
|
||
try {
|
||
$pdo = new PDO(
|
||
"mysql:host={$config['db_host']};dbname={$config['db_name']};charset=utf8mb4",
|
||
$config['db_user'],
|
||
$config['db_pass'],
|
||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
||
);
|
||
|
||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM registrations WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)");
|
||
$stmt->execute();
|
||
$recent_registrations = $stmt->fetchColumn();
|
||
|
||
if ($recent_registrations >= 3) {
|
||
$error = "Слишком много регистраций за последний час. Попробуйте позже.";
|
||
} else {
|
||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE username = ?");
|
||
$stmt->execute([$username]);
|
||
if ($stmt->fetchColumn() > 0) {
|
||
$error = "Пользователь с таким именем уже существует";
|
||
} else {
|
||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||
|
||
$stmt = $pdo->prepare("INSERT INTO users (username, password, pgp_key) VALUES (?, ?, ?)");
|
||
$stmt->execute([$username, $hashed_password, $pgp_key]);
|
||
|
||
$stmt = $pdo->prepare("INSERT INTO registrations (created_at) VALUES (NOW())");
|
||
$stmt->execute();
|
||
|
||
$success = "Регистрация успешна! Теперь вы можете войти.";
|
||
}
|
||
}
|
||
} catch (PDOException $e) {
|
||
$error = "Ошибка сервера";
|
||
}
|
||
}
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Регистрация</title>
|
||
<link rel="stylesheet" href="style.css">
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<h1>Регистрация</h1>
|
||
<?php if (isset($error)): ?>
|
||
<div class="error"><?php echo $error; ?></div>
|
||
<?php endif; ?>
|
||
<?php if (isset($success)): ?>
|
||
<div class="success"><?php echo $success; ?></div>
|
||
<?php endif; ?>
|
||
<form method="POST" action="">
|
||
<div class="form-group">
|
||
<label for="username">Имя пользователя:</label>
|
||
<input type="text" id="username" name="username" required>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="password">Пароль:</label>
|
||
<input type="password" id="password" name="password" required>
|
||
</div>
|
||
<div class="form-group">
|
||
<label for="pgp_key">PGP ключ (опционально):</label>
|
||
<textarea id="pgp_key" name="pgp_key" rows="5"></textarea>
|
||
</div>
|
||
<button type="submit">Зарегистрироваться</button>
|
||
</form>
|
||
<p>Уже есть аккаунт? <a href="login.php">Войти</a></p>
|
||
</div>
|
||
</body>
|
||
</html>
|