mirror of
https://git.sr.ht/~iwakuralain/text0Nly
synced 2025-07-27 07:30:31 +00:00
okay
This commit is contained in:
parent
bf0536ac9c
commit
71dd22c304
@ -33,6 +33,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$stmt = $db->prepare('UPDATE users SET is_blocked = 0 WHERE username = ?');
|
||||
$stmt->execute([$username]);
|
||||
$success = "User $username has been unbanned";
|
||||
} elseif ($_POST['action'] === 'preventive_ban') {
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/', $username)) {
|
||||
$error = "Invalid username format";
|
||||
} else {
|
||||
$stmt = $db->prepare('INSERT INTO banned_usernames (username) VALUES (?)');
|
||||
try {
|
||||
$stmt->execute([$username]);
|
||||
$success = "Username $username has been preventively banned";
|
||||
} catch (PDOException $e) {
|
||||
$error = "Username already banned";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,6 +112,15 @@ $users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<div class="success"><?= htmlspecialchars($success) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="preventive-ban">
|
||||
<h2>Preventive Ban</h2>
|
||||
<form method="post" class="ban-form">
|
||||
<input type="text" name="username" placeholder="Username to ban" required pattern="[a-zA-Z0-9_]+" maxlength="50">
|
||||
<input type="hidden" name="action" value="preventive_ban">
|
||||
<button type="submit" class="ban-btn">Ban Username</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -31,27 +31,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
} else if (strlen($pgp_key) > 4096) {
|
||||
$error = 'PGP key is too long';
|
||||
} else {
|
||||
$stmt = $db->prepare('SELECT COUNT(*) FROM registrations WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)');
|
||||
$stmt->execute();
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
if ($count >= 20) {
|
||||
$error = 'Registration limit exceeded';
|
||||
$stmt = $db->prepare('SELECT COUNT(*) FROM banned_usernames WHERE username = ?');
|
||||
$stmt->execute([$username]);
|
||||
if ($stmt->fetchColumn() > 0) {
|
||||
$error = 'This username is not allowed';
|
||||
} else {
|
||||
try {
|
||||
$stmt = $db->prepare('INSERT INTO users (username, password, pgp_key, login_attempts, last_attempt) VALUES (?, ?, ?, 0, NOW())');
|
||||
$stmt->execute([
|
||||
$username,
|
||||
password_hash($password, PASSWORD_DEFAULT, ['cost' => 12]),
|
||||
$pgp_key
|
||||
]);
|
||||
$stmt = $db->prepare('SELECT COUNT(*) FROM registrations WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)');
|
||||
$stmt->execute();
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO registrations () VALUES ()');
|
||||
$stmt->execute();
|
||||
if ($count >= 20) {
|
||||
$error = 'Registration limit exceeded';
|
||||
} else {
|
||||
try {
|
||||
$stmt = $db->prepare('INSERT INTO users (username, password, pgp_key, login_attempts, last_attempt) VALUES (?, ?, ?, 0, NOW())');
|
||||
$stmt->execute([
|
||||
$username,
|
||||
password_hash($password, PASSWORD_DEFAULT, ['cost' => 12]),
|
||||
$pgp_key
|
||||
]);
|
||||
|
||||
$success = 'Registration successful';
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Username already exists';
|
||||
$stmt = $db->prepare('INSERT INTO registrations () VALUES ()');
|
||||
$stmt->execute();
|
||||
|
||||
$success = 'Registration successful';
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Username already exists';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,3 +22,9 @@ DELIMITER ;
|
||||
|
||||
CALL migrate_if_needed();
|
||||
DROP PROCEDURE IF EXISTS migrate_if_needed;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS banned_usernames (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user