Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
define('ENOTF_PREREG', true); // Wird das Voranmeldungssystem des eNOTF verwendet? (true = ja, false = nein)
define('ENOTF_USE_PIN', true); // Wird die PIN-Funktion des eNOTF verwendet? (true = ja, false = nein)
define('ENOTF_PIN', '1234'); // PIN für den Zugang zum eNOTF - 4-6 Zahlen (nur relevant, wenn ENOTF_USE_PIN auf true gesetzt ist)
define('REGISTRATION_MODE', 'open'); // Registrierungsmodus: open = für jeden möglich, code = nur mit Code, closed = keine Registrierung
define('LANG', 'de'); // Sprache des Systems (de = Deutsch, en = Englisch) // AKTUELL OHNE FUNKTION!
define('BASE_PATH', '/'); // Basis-Pfad des Systems (z.B. /intraRP/ für https://domain.de/intraRP/)
42 changes: 0 additions & 42 deletions assets/database/create_intra_config_02112025.php

This file was deleted.

23 changes: 23 additions & 0 deletions assets/database/create_intra_registration_codes_02112025.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
try {
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS `intra_registration_codes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(255) NOT NULL,
`created_by` int(11) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`used_by` int(11) DEFAULT NULL,
`used_at` timestamp NULL DEFAULT NULL,
`is_used` tinyint(1) DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`),
KEY `created_by` (`created_by`),
KEY `used_by` (`used_by`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL;

$pdo->exec($sql);
} catch (PDOException $e) {
$message = $e->getMessage();
echo $message;
}
83 changes: 70 additions & 13 deletions auth/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,77 @@
}
}
} else {
$insertStmt = $pdo->prepare("
INSERT INTO intra_users (discord_id, username, fullname, role, full_admin)
VALUES (:discord_id, :username, NULL, :role, :full_admin)
");
$insertStmt->execute([
'discord_id' => $discordId,
'username' => $username,
'role' => $defaultRole['id'],
'full_admin' => 0
]);
// Check registration mode
$registrationMode = defined('REGISTRATION_MODE') ? REGISTRATION_MODE : 'open';

if ($registrationMode === 'closed') {
// No registration allowed - redirect to login with error message
$_SESSION['registration_error'] = 'Registrierung ist derzeit geschlossen. Bitte wenden Sie sich an einen Administrator.';
header('Location: ' . BASE_PATH . 'login.php');
exit;
} elseif ($registrationMode === 'code') {
// Check for valid registration code
$code = $_SESSION['registration_code'] ?? null;

if (!$code) {
// Redirect to login page to enter code
$_SESSION['pending_discord_id'] = $discordId;
$_SESSION['registration_error'] = 'Bitte geben Sie Ihren Registrierungscode ein.';
header('Location: ' . BASE_PATH . 'login.php?require_code=1');
exit;
}

$codeStmt = $pdo->prepare("SELECT * FROM intra_registration_codes WHERE code = :code AND is_used = 0");
$codeStmt->execute(['code' => $code]);
$codeRecord = $codeStmt->fetch();

if (!$codeRecord) {
unset($_SESSION['registration_code']);
$_SESSION['pending_discord_id'] = $discordId;
$_SESSION['registration_error'] = 'Ungültiger oder bereits verwendeter Registrierungscode.';
header('Location: ' . BASE_PATH . 'login.php?require_code=1');
exit;
}

$stmt = $pdo->prepare("SELECT * FROM intra_users WHERE discord_id = :discord_id");
$stmt->execute(['discord_id' => $discordId]);
$user = $stmt->fetch();
// Create user with the code
$insertStmt = $pdo->prepare("
INSERT INTO intra_users (discord_id, username, fullname, role, full_admin)
VALUES (:discord_id, :username, NULL, :role, :full_admin)
");
$insertStmt->execute([
'discord_id' => $discordId,
'username' => $username,
'role' => $defaultRole['id'],
'full_admin' => 0
]);

// Mark code as used
$userId = $pdo->lastInsertId();
$updateCodeStmt = $pdo->prepare("UPDATE intra_registration_codes SET is_used = 1, used_by = :user_id, used_at = NOW() WHERE id = :code_id");
$updateCodeStmt->execute(['user_id' => $userId, 'code_id' => $codeRecord['id']]);

unset($_SESSION['registration_code']);

$stmt = $pdo->prepare("SELECT * FROM intra_users WHERE discord_id = :discord_id");
$stmt->execute(['discord_id' => $discordId]);
$user = $stmt->fetch();
} else {
// Open registration
$insertStmt = $pdo->prepare("
INSERT INTO intra_users (discord_id, username, fullname, role, full_admin)
VALUES (:discord_id, :username, NULL, :role, :full_admin)
");
$insertStmt->execute([
'discord_id' => $discordId,
'username' => $username,
'role' => $defaultRole['id'],
'full_admin' => 0
]);

$stmt = $pdo->prepare("SELECT * FROM intra_users WHERE discord_id = :discord_id");
$stmt->execute(['discord_id' => $discordId]);
$user = $stmt->fetch();
}

$_SESSION['userid'] = $user['id'];
$_SESSION['cirs_user'] = $user['fullname'];
Expand Down
96 changes: 96 additions & 0 deletions auth/register-code.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
require_once __DIR__ . '/../assets/config/config.php';
require_once __DIR__ . '/../assets/config/database.php';

session_start();

if (!isset($_GET['discord_id'])) {
header('Location: ' . BASE_PATH . 'login.php');
exit;
}

$discordId = $_GET['discord_id'];

// Check if user already exists
$stmt = $pdo->prepare("SELECT id FROM intra_users WHERE discord_id = :discord_id");
$stmt->execute(['discord_id' => $discordId]);
if ($stmt->fetch()) {
header('Location: ' . BASE_PATH . 'auth/discord.php');
exit;
}

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$code = trim($_POST['code'] ?? '');

if (empty($code)) {
$error = 'Bitte geben Sie einen Registrierungscode ein.';
} else {
// Verify the code exists and is not used
$codeStmt = $pdo->prepare("SELECT 1 FROM intra_registration_codes WHERE code = :code AND is_used = 0");
$codeStmt->execute(['code' => $code]);

if ($codeStmt->fetchColumn()) {
$_SESSION['registration_code'] = $code;
header('Location: ' . BASE_PATH . 'auth/discord.php');
exit;
} else {
$error = 'Ungültiger oder bereits verwendeter Registrierungscode.';
}
}
}
?>
<!DOCTYPE html>
<html>

<head>
<?php
$SITE_TITLE = 'Registrierungscode';
include __DIR__ . '/../assets/components/_base/admin/head.php'; ?>
</head>

<body data-bs-theme="dark" id="alogin" class="container-full position-relative">
<div id="video-background">
<iframe
src="https://www.youtube.com/embed/9z1qetAaiBA?autoplay=1&mute=1&loop=1&playlist=9z1qetAaiBA&controls=0&showinfo=0&modestbranding=1&rel=0&iv_load_policy=3&disablekb=1&fs=0"
frameborder="0"
allow="autoplay; encrypted-media"
allowfullscreen>
</iframe>
</div>

<div class="container d-flex justify-content-center align-items-center flex-column h-100">
<div class="row" style="width:30%">
<div class="col text-center">
<img src="<?= SYSTEM_LOGO ?>" alt="intraRP Logo" class="mb-4" width="75%" height="auto">
<div class="card px-4 py-3">
<h1 id="loginHeader">Registrierungscode</h1>
<p class="subtext mb-4">Bitte geben Sie Ihren Registrierungscode ein, um fortzufahren.</p>

<?php if ($error): ?>
<div class="alert alert-danger" role="alert">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>

<form method="POST">
<div class="mb-3">
<input type="text" class="form-control" name="code" placeholder="Registrierungscode" required autofocus>
</div>
<button type="submit" class="btn btn-primary w-100">Weiter</button>
</form>

<div class="mt-3">
<a href="<?= BASE_PATH ?>login.php" class="btn btn-secondary w-100">Zurück zum Login</a>
</div>
</div>
</div>
</div>
<p class="mt-3 small text-center">
&copy; <?php echo date("Y") ?> <a href="https://intrarp.de">intraRP</a> | Alle Rechte vorbehalten
</p>
</div>
</body>

</html>
Loading