Files
FWS-TEMPLATE-Website-OnePage/admin/bugs/register.php
T
BlackAngelTV 83933d0621 fix(admin): build admin URLs against the dynamic base URL
Preview thumbnails for package screenshots and the API test link
assumed a root deployment; use fws_url() and derive the scheme
from the request instead of hardcoding https.
2026-09-16 14:35:41 +02:00

159 lines
7.1 KiB
PHP

<?php
/**
* FWS Linux — Inscription au panneau des signalements.
*
* La personne reçoit un code d'invitation À USAGE UNIQUE (généré dans le
* panneau admin, onglet « Invitations & comptes »), puis crée ici son
* compte avec un nom d'utilisateur et un mot de passe.
*
* URL : https://fwslinux.fr/admin/bugs/register.php
*/
declare(strict_types=1);
require __DIR__ . '/../../api/bugs/db.php';
function h(?string $s): string
{
return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');
}
$error = null;
$ok = false;
/* Petit anti-spam : champ piège */
$honeypot = trim((string) ($_POST['website'] ?? ''));
$submitted = ($_SERVER['REQUEST_METHOD'] === 'POST') && $honeypot === '';
if ($submitted) {
$code = trim((string) ($_POST['code'] ?? ''));
$username = trim((string) ($_POST['username'] ?? ''));
$password = (string) ($_POST['password'] ?? '');
$confirm = (string) ($_POST['password2'] ?? '');
try {
$pdo = fws_bugs_db();
/* 1) Le code est-il valable ? */
$invite = fws_bugs_find_invite($pdo, $code);
if ($invite === null) {
$error = 'Ce code d\'invitation est inconnu. Vérifiez qu\'il a bien été copié.';
} elseif ($invite['revoked_at'] !== null) {
$error = 'Ce code d\'invitation a été révoqué. Demandez-en un nouveau.';
} elseif ($invite['used_by'] !== null) {
$error = 'Ce code d\'invitation a déjà été utilisé.';
} elseif ($invite['expires_at'] !== null && $invite['expires_at'] < date('Y-m-d H:i:s')) {
$error = 'Ce code d\'invitation a expiré. Demandez-en un nouveau.';
} elseif (!preg_match('/^[A-Za-z0-9_.\-]{2,32}$/', $username)) {
$error = 'Nom d\'utilisateur invalide (2 à 32 caractères : lettres, chiffres, . _ -).';
} elseif (strlen($password) < 8) {
$error = 'Mot de passe trop court (8 caractères minimum).';
} elseif ($password !== $confirm) {
$error = 'Les deux mots de passe ne correspondent pas.';
}
/* 2) Création du compte + consommation du code (transaction) */
if ($error === null) {
$pdo->beginTransaction();
try {
$hash = password_hash($password, PASSWORD_DEFAULT);
$uid = fws_bugs_next_id($pdo, 'admin_users');
$ins = $pdo->prepare('INSERT INTO admin_users (id, username, password_hash) VALUES (:id, :u, :h)');
$ins->execute([':id' => $uid, ':u' => $username, ':h' => $hash]);
$claim = $pdo->prepare("UPDATE invite_codes SET used_by = :uid, used_at = datetime('now') WHERE id = :id AND used_by IS NULL");
$claim->execute([':uid' => $uid, ':id' => (int) $invite['id']]);
if ($claim->rowCount() !== 1) {
throw new RuntimeException('Code déjà utilisé entre-temps.');
}
$pdo->commit();
$ok = true;
} catch (Throwable $e) {
$pdo->rollBack();
if ($pdo->errorInfo()[1] === 19 && strpos((string) $e->getMessage(), 'UNIQUE') !== false) {
$error = 'Ce nom d\'utilisateur est déjà pris. Choisissez-en un autre.';
} else {
error_log('[fws-bugs] inscription : ' . $e->getMessage());
$error = 'Erreur interne lors de l\'inscription. Réessayez.';
}
}
}
} catch (Throwable $e) {
$error = 'Erreur base de données : ' . h($e->getMessage());
}
}
/* Succès → retour à la page de connexion avec un message */
if ($ok) {
header('Location: index.php?registered=1');
exit;
}
$fwsScheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$baseUrl = $fwsScheme . '://' . ($_SERVER['HTTP_HOST'] ?? 'fwslinux.fr');
$codeValue = $submitted ? $code : '';
$userValue = $submitted ? $username : '';
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Créer un compte — Signalements FWS</title>
<style>
:root { color-scheme: dark; }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: #0f172a; color: #e2e8f0; }
.wrap { max-width: 520px; margin: 0 auto; padding: 40px 16px; }
.card { background: #111c33; border: 1px solid #1e293b; border-radius: 14px; padding: 28px; }
h1 { font-size: 1.25rem; margin-top: 0; }
label { font-size: .85rem; color: #cbd5e1; display: block; margin-top: 14px; }
input[type=text], input[type=password], input[type=code] {
width: 100%; padding: 10px 12px; margin: 6px 0 2px;
background: #0b1120; border: 1px solid #334155; border-radius: 8px; color: #e2e8f0; font-size: .95rem;
}
input.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .08em; text-transform: uppercase; }
button { margin-top: 20px; padding: 11px 18px; border: 0; border-radius: 8px; background: #0284c7; color: #fff; font-size: 1rem; cursor: pointer; width: 100%; }
button:hover { background: #0369a1; }
.flash { padding: 10px 12px; border-radius: 8px; font-size: .88rem; margin-bottom: 14px; }
.flash.err { background: #3d1414; color: #ffa198; }
.hint { font-size: .8rem; color: #64748b; margin-top: 4px; }
.back { display: inline-block; margin-top: 18px; font-size: .85rem; color: #94a3b8; text-decoration: none; }
.note { font-size: .85rem; color: #94a3b8; background: #0b1120; border: 1px solid #1e293b; border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; line-height: 1.5; }
</style>
</head>
<body>
<div class="wrap">
<div class="card">
<h1>🎟️ Créer un compte</h1>
<p class="note">Tu as reçu un <strong>code d'invitation à usage unique</strong> de l'équipe FWS.
Saisis-le ci-dessous puis choisis ton nom d'utilisateur et ton mot de passe.</p>
<?php if ($error): ?><div class="flash err"><?= h($error) ?></div><?php endif; ?>
<form method="post" autocomplete="on">
<label for="code">Code d'invitation</label>
<input type="text" id="code" name="code" class="code" required autofocus
value="<?= h($codeValue) ?>" placeholder="K7QM-2H4D-X9BP">
<label for="username">Nom d'utilisateur</label>
<input type="text" id="username" name="username" required value="<?= h($userValue) ?>"
placeholder="ex : alice" pattern="[A-Za-z0-9_.\-]{2,32}">
<div class="hint">2 à 32 caractères : lettres, chiffres, . _ -</div>
<label for="password">Mot de passe</label>
<input type="password" id="password" name="password" required minlength="8" placeholder="8 caractères minimum">
<label for="password2">Confirmer le mot de passe</label>
<input type="password" id="password2" name="password2" required minlength="8">
<input name="website" style="display:none" tabindex="-1" autocomplete="off">
<button type="submit">Créer mon compte</button>
</form>
<a class="back" href="index.php">← Retour à la connexion</a>
</div>
</div>
</body>
</html>