172 lines
6.7 KiB
PHP
172 lines
6.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 3) . '/src/App/bootstrap.php';
|
|
|
|
use App\ConfigLoader;
|
|
use App\RegistrationService;
|
|
|
|
session_start();
|
|
|
|
$projectRoot = dirname(__DIR__, 3);
|
|
$registration = new RegistrationService($projectRoot, ConfigLoader::load($projectRoot, 'registration'));
|
|
|
|
if (!$registration->isEnabled()) {
|
|
http_response_code(404);
|
|
echo 'Registrierung ist deaktiviert.';
|
|
exit;
|
|
}
|
|
|
|
$csrfToken = (string) ($_SESSION['registration_form_token'] ?? '');
|
|
|
|
if ($csrfToken === '') {
|
|
$csrfToken = bin2hex(random_bytes(16));
|
|
$_SESSION['registration_form_token'] = $csrfToken;
|
|
}
|
|
|
|
$errors = [];
|
|
$submitted = false;
|
|
$createdRequest = null;
|
|
$form = [
|
|
'username' => '',
|
|
'given_name' => '',
|
|
'family_name' => '',
|
|
'email' => '',
|
|
'note' => '',
|
|
'password' => '',
|
|
'password_confirm' => '',
|
|
];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$form = [
|
|
'username' => trim((string) ($_POST['username'] ?? '')),
|
|
'given_name' => trim((string) ($_POST['given_name'] ?? '')),
|
|
'family_name' => trim((string) ($_POST['family_name'] ?? '')),
|
|
'email' => trim((string) ($_POST['email'] ?? '')),
|
|
'note' => trim((string) ($_POST['note'] ?? '')),
|
|
'password' => (string) ($_POST['password'] ?? ''),
|
|
'password_confirm' => (string) ($_POST['password_confirm'] ?? ''),
|
|
];
|
|
|
|
$postedToken = (string) ($_POST['csrf_token'] ?? '');
|
|
|
|
if ($postedToken === '' || !hash_equals($csrfToken, $postedToken)) {
|
|
$errors[] = 'Die Formularprüfung ist fehlgeschlagen. Bitte versuche es erneut.';
|
|
} else {
|
|
$result = $registration->submit($form);
|
|
|
|
if (($result['success'] ?? false) !== true) {
|
|
$errors = array_values(array_map('strval', (array) ($result['errors'] ?? [])));
|
|
} else {
|
|
$submitted = true;
|
|
$createdRequest = $result['request'] ?? null;
|
|
$csrfToken = bin2hex(random_bytes(16));
|
|
$_SESSION['registration_form_token'] = $csrfToken;
|
|
$form = [
|
|
'username' => '',
|
|
'given_name' => '',
|
|
'family_name' => '',
|
|
'email' => '',
|
|
'note' => '',
|
|
'password' => '',
|
|
'password_confirm' => '',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
?><!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Registrierung anfragen</title>
|
|
<link rel="stylesheet" href="/assets/auth/login.css">
|
|
</head>
|
|
<body>
|
|
<main class="login-shell">
|
|
<section class="login-panel login-panel-wide">
|
|
<div class="login-panel-top">
|
|
<p class="login-kicker">Kusche.Berlin</p>
|
|
<h1>Registrierung anfragen</h1>
|
|
<p class="login-copy">Neue Konten werden nicht sofort freigeschaltet. Deine Anfrage wird geprüft und erst danach für LDAP, NAS und Desktop vorbereitet.</p>
|
|
</div>
|
|
|
|
<?php if ($submitted): ?>
|
|
<div class="login-notice login-notice-success">
|
|
<strong>Anfrage gespeichert.</strong>
|
|
<p>Dein Zugang wurde noch nicht freigeschaltet. Eine berechtigte Person prüft nun die Registrierung.</p>
|
|
<?php if (is_array($createdRequest)): ?>
|
|
<p class="login-meta-inline">Vorgangs-ID: <?= htmlspecialchars((string) ($createdRequest['id'] ?? ''), ENT_QUOTES) ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($errors !== []): ?>
|
|
<div class="login-notice login-notice-error">
|
|
<strong>Bitte prüfen</strong>
|
|
<ul class="login-list">
|
|
<?php foreach ($errors as $error): ?>
|
|
<li><?= htmlspecialchars($error, ENT_QUOTES) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form class="login-form" method="post" action="/auth/register">
|
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES) ?>">
|
|
|
|
<div class="login-form-grid">
|
|
<label class="login-field">
|
|
<span>Benutzername</span>
|
|
<input type="text" name="username" value="<?= htmlspecialchars($form['username'], ENT_QUOTES) ?>" required>
|
|
</label>
|
|
|
|
<label class="login-field">
|
|
<span>E-Mail</span>
|
|
<input type="email" name="email" value="<?= htmlspecialchars($form['email'], ENT_QUOTES) ?>" required>
|
|
</label>
|
|
|
|
<label class="login-field">
|
|
<span>Vorname</span>
|
|
<input type="text" name="given_name" value="<?= htmlspecialchars($form['given_name'], ENT_QUOTES) ?>" required>
|
|
</label>
|
|
|
|
<label class="login-field">
|
|
<span>Nachname</span>
|
|
<input type="text" name="family_name" value="<?= htmlspecialchars($form['family_name'], ENT_QUOTES) ?>" required>
|
|
</label>
|
|
</div>
|
|
|
|
<label class="login-field">
|
|
<span>Zusätzliche Info</span>
|
|
<textarea name="note" rows="5" placeholder="Optional: Bezug zur Familie, Einladung, gewünschte Nutzung, Rückfragekontakt"><?= htmlspecialchars($form['note'], ENT_QUOTES) ?></textarea>
|
|
</label>
|
|
|
|
<div class="login-form-grid">
|
|
<label class="login-field">
|
|
<span>Passwort</span>
|
|
<input type="password" name="password" value="" required>
|
|
</label>
|
|
|
|
<label class="login-field">
|
|
<span>Passwort wiederholen</span>
|
|
<input type="password" name="password_confirm" value="" required>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="login-notice login-notice-info">
|
|
<strong>Wichtig</strong>
|
|
<p>Das Passwort wird verschlüsselt zwischengespeichert und bei Freigabe direkt für LDAP und SMB gesetzt. Neue Registrierungen erhalten zunächst trotzdem keinen aktiven Desktop-Zugang.</p>
|
|
</div>
|
|
|
|
<div class="login-actions">
|
|
<button class="login-button login-button-primary" type="submit">Registrierung absenden</button>
|
|
<a class="login-button login-button-secondary" href="/auth/login">Zurück zum Login</a>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</main>
|
|
</body>
|
|
</html>
|