121 lines
5.4 KiB
PHP
121 lines
5.4 KiB
PHP
<?php
|
|
header("Cache-Control: no-cache, no-store, must-revalidate");
|
|
header("Pragma: no-cache");
|
|
header("Expires: 0");
|
|
require_once __DIR__ . '/session.php';
|
|
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
$inviteCode = $_POST['invite_code'] ?? '';
|
|
|
|
if ($username && $email && $password) {
|
|
// Strict invite code validation (Private by default)
|
|
$requireInvite = true;
|
|
if (defined('REQUIRE_INVITE_CODE')) {
|
|
$requireInvite = REQUIRE_INVITE_CODE;
|
|
}
|
|
|
|
if ($requireInvite) {
|
|
if (empty($inviteCode)) {
|
|
$error = "An invitation code is required to register.";
|
|
} else {
|
|
$stmt = db()->prepare("SELECT id FROM servers WHERE invite_code = ?");
|
|
$stmt->execute([$inviteCode]);
|
|
$server = $stmt->fetch();
|
|
if (!$server) {
|
|
$error = "Invalid invitation code.";
|
|
}
|
|
}
|
|
}
|
|
|
|
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 default server or the one from invite code
|
|
$serverId = 1; // Default
|
|
if (isset($server) && $server) {
|
|
$serverId = $server['id'];
|
|
}
|
|
|
|
$stmt = db()->prepare("INSERT IGNORE INTO server_members (server_id, user_id) VALUES (?, ?)");
|
|
$stmt->execute([$serverId, $userId]);
|
|
|
|
$_SESSION['user_id'] = $userId;
|
|
header('Location: ../index.php');
|
|
exit;
|
|
} catch (Exception $e) {
|
|
$error = "Registration failed: " . $e->getMessage();
|
|
}
|
|
}
|
|
} else {
|
|
$error = "Please fill all fields.";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Register | Discord Clone</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="../assets/css/discord.css">
|
|
<style>
|
|
body { background-color: #313338; display: flex; align-items: center; justify-content: center; height: 100vh; }
|
|
.auth-card { background-color: #2b2d31; padding: 32px; border-radius: 8px; width: 100%; max-width: 480px; box-shadow: 0 2px 10px rgba(0,0,0,0.2); border: 3px solid #f04747; }
|
|
.form-label { color: #b5bac1; font-size: 12px; font-weight: bold; text-transform: uppercase; }
|
|
.form-control { background-color: #1e1f22; border: none; color: #dbdee1; padding: 10px; }
|
|
.form-control:focus { background-color: #1e1f22; color: #dbdee1; box-shadow: none; }
|
|
.btn-blurple { background-color: #5865f2; color: white; width: 100%; font-weight: bold; margin-top: 20px; }
|
|
.btn-blurple:hover { background-color: #4752c4; color: white; }
|
|
.auth-footer { color: #949ba4; font-size: 14px; margin-top: 10px; }
|
|
.auth-footer a { color: #00a8fc; text-decoration: none; }
|
|
@keyframes blink { 0% { border-color: #f04747; } 50% { border-color: transparent; } 100% { border-color: #f04747; } }
|
|
.invite-box { border: 4px solid #f04747; padding: 15px; border-radius: 8px; margin-bottom: 25px; background: rgba(240, 71, 71, 0.1); animation: blink 1s infinite; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="auth-card">
|
|
<h3 class="text-center mb-4">Create an account</h3>
|
|
<?php if($error): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
<form method="POST">
|
|
<!-- INVITE CODE FIELD - CRITICAL -->
|
|
<div class="invite-box">
|
|
<label class="form-label" style="color: #f04747 !important; font-size: 16px;">REQUIRED: INVITE CODE</label>
|
|
<div class="small mb-1" style="color: #fff !important; font-weight: bold;">Enter the code from Server Settings.</div>
|
|
<input type="text" name="invite_code" class="form-control" placeholder="INVITE CODE HERE" required style="border: 2px solid #f04747; font-size: 20px; text-align: center; font-weight: bold;">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Username</label>
|
|
<input type="text" name="username" class="form-control" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Email</label>
|
|
<input type="email" name="email" class="form-control" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Password</label>
|
|
<input type="password" name="password" class="form-control" required>
|
|
</div>
|
|
|
|
|
|
|
|
<button type="submit" class="btn btn-blurple">Continue</button>
|
|
<div class="text-center mt-2" style="color: #4e5058; font-size: 10px;">Version: <?php echo time(); ?></div>
|
|
<div class="auth-footer">
|
|
Already have an account? <a href="login.php">Login</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|