invite code pour créer un compte

This commit is contained in:
Flatlogic Bot 2026-02-18 16:22:01 +00:00
parent 5329017efa
commit a763e6e5b1
4 changed files with 46 additions and 15 deletions

View File

@ -6,23 +6,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$invite_code = $_POST['invite_code'] ?? '';
if ($username && $email && $password) {
$hash = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = db()->prepare("INSERT INTO users (username, display_name, email, password_hash) VALUES (?, ?, ?, ?)");
$stmt->execute([$username, $username, $email, $hash]);
$userId = db()->lastInsertId();
// Add to default server
$stmt = db()->prepare("INSERT IGNORE INTO server_members (server_id, user_id) VALUES (1, ?)");
$stmt->execute([$userId]);
$server_id = 1; // Default server
if (PRIVATE_REGISTRATION) {
if (empty($invite_code)) {
$error = "An invitation code is required.";
} else {
$stmt = db()->prepare("SELECT id FROM servers WHERE invite_code = ?");
$stmt->execute([$invite_code]);
$server = $stmt->fetch();
if (!$server) {
$error = "Invalid invitation code.";
} else {
$server_id = $server['id'];
}
}
}
$_SESSION['user_id'] = $userId;
header('Location: ../index.php');
exit;
} catch (Exception $e) {
$error = "Registration failed: " . $e->getMessage();
if (!$error) {
$hash = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = db()->prepare("INSERT INTO users (username, display_name, email, password_hash) VALUES (?, ?, ?, ?)");
$stmt->execute([$username, $username, $email, $hash]);
$userId = db()->lastInsertId();
// Add to the appropriate server
$stmt = db()->prepare("INSERT IGNORE INTO server_members (server_id, user_id) VALUES (?, ?)");
$stmt->execute([$server_id, $userId]);
$_SESSION['user_id'] = $userId;
header('Location: ../index.php?server_id=' . $server_id);
exit;
} catch (Exception $e) {
$error = "Registration failed: " . $e->getMessage();
}
}
} else {
$error = "Please fill all fields.";
@ -67,6 +86,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<label class="form-label">Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<?php if (PRIVATE_REGISTRATION): ?>
<div class="mb-3">
<label class="form-label">Invite Code</label>
<input type="text" name="invite_code" class="form-control" placeholder="Enter invitation code" required>
</div>
<?php endif; ?>
<button type="submit" class="btn btn-blurple">Continue</button>
<div class="auth-footer">
Already have an account? <a href="login.php">Login</a>

View File

@ -1 +1 @@
{"42293ef053eb80b0":{"id":"42293ef053eb80b0","user_id":2,"name":"swefpifh ᵇʰᶠʳ","avatar_url":"","last_seen":1771431325495}}
{"42293ef053eb80b0":{"id":"42293ef053eb80b0","user_id":2,"name":"swefpifh ᵇʰᶠʳ","avatar_url":"","last_seen":1771431670668}}

View File

@ -5,6 +5,9 @@ define('DB_NAME', 'app_38443');
define('DB_USER', 'app_38443');
define('DB_PASS', '888f6481-a87b-421a-a4bd-c80fa3c5a57b');
// Registration mode: true for private (requires invite code), false for public
define('PRIVATE_REGISTRATION', true);
function db() {
static $pdo;
if (!$pdo) {

View File

@ -639,3 +639,6 @@
2026-02-18 16:04:48 - GET /?server_id=1&channel_id=18 - POST: []
2026-02-18 16:12:25 - GET /?fl_project=38443 - POST: []
2026-02-18 16:14:55 - GET /?server_id=1&channel_id=18 - POST: []
2026-02-18 16:17:10 - GET / - POST: []
2026-02-18 16:20:19 - GET /?fl_project=38443 - POST: []
2026-02-18 16:21:39 - GET /index.php - POST: []