-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_code.php
More file actions
88 lines (74 loc) · 2.67 KB
/
Copy pathverify_code.php
File metadata and controls
88 lines (74 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
session_start();
require_once 'config.php';
$email = $_GET['email'] ?? '';
$error = '';
if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false && isset($_SESSION['dev_code'])) {
$code = $_SESSION['dev_code'];
$email = $_SESSION['dev_email'];
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'];
$code = $_POST['code'];
try {
$stmt = $pdo->prepare("
SELECT id, login_code, login_code_expires
FROM c_users
WHERE email = ?
");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user &&
$user['login_code'] === $code &&
strtotime($user['login_code_expires']) > time()) {
$_SESSION['user_id'] = $user['id'];
// Réinitialisation du code
$stmt = $pdo->prepare("
UPDATE c_users
SET login_code = NULL, login_code_expires = NULL
WHERE id = ?
");
$stmt->execute([$user['id']]);
header("Location: dashboard.php");
exit();
} else {
$error = "Code invalide ou expiré.";
}
} catch (Exception $e) {
$error = "Erreur lors de la vérification : " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vérification du code</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<h1>Vérification du code</h1>
<?php if ($error): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false && isset($_SESSION['dev_code'])): ?>
<div class="success">
<strong>Mode développement :</strong>
Votre code est <strong><?= $_SESSION['dev_code'] ?></strong>
</div>
<?php endif; ?>
<p>Un code à 6 chiffres a été envoyé à <?= htmlspecialchars($email) ?>.</p>
<form action="verify_code.php" method="post">
<input type="hidden" name="email" value="<?= htmlspecialchars($email) ?>">
<label for="code">Code :</label>
<input type="text" id="code" name="code" pattern="\d{6}" maxlength="6" required>
<button type="submit" class="btn">Se connecter</button>
</form>
<p style="margin-top: 20px;">
<a href="index.php">Retour à la page de connexion</a>
</p>
</div>
</body>
</html>