0% found this document useful (0 votes)
9 views3 pages

Duck - Ai - 2025 05 20 - 17 18 32

Uploaded by

Broli Tiako
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Duck - Ai - 2025 05 20 - 17 18 32

Uploaded by

Broli Tiako
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Cette conversation a été générée avec Duck.ai (https://duck.

ai) à l'aide du modèle


GPT-4o mini d'OpenAI. Les chats IA peuvent afficher des informations inexactes ou
offensantes (voir https://duckduckgo.com/duckai/privacy-terms pour en savoir plus).

====================

Message 1 sur 1 de l'utilisateur - 16/05/2025 18:43:39:


<?php
session_start();
require 'config/bd.php';
require 'vendor/autoload.php'; // Assurez-vous d'inclure l'autoloader de Composer

// Vérifiez si l'utilisateur est connecté


if (!isset($_SESSION['user_id'])) {
header('Location: load.php?redirect=Login.php');
exit();
}

// Affichage des notifications de session


function displayToast($message, $type = 'success') {
$bgColor = $type === 'error' ? 'bg-red-500' : ($type === 'warning' ? 'bg-
orange-500' : 'bg-green-500');
echo "
<div class='toast flex items-center justify-center p-4 $bgColor text-white
rounded shadow-lg max-w-xs fixed top-4 right-4 z-50'>
<span>$message</span>
<button class='ml-4 bg-red-500 text-white py-1 px-2 rounded'
onclick='this.parentElement.remove()'>X</button>
</div>
";
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {


$email = trim($_POST['Email']);
$stmt = $pdo->prepare("SELECT * FROM registre WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();

if (!$user) {
$_SESSION['toast_message'] = "L'email est incorrect.";
$_SESSION['toast_type'] = "error";
header('Location: verif_email.php');
exit();
} else {
// Générer le code QR
$ga = new PHPGangsta_GoogleAuthenticator();
$qrCodeUrl = $ga->getQRCodeGoogleUrl('MonApp',
$user['google_auth_secret']);
$_SESSION['qr_code_url'] = $qrCodeUrl;
$_SESSION['email'] = $email; // Stocker l'email dans la session pour la
vérification ultérieure
header('Location: Qr_code.php');
exit();
}
}
?>

//Qr_code.php
GPT-4o mini:
It looks like you're working on a PHP application that involves user authentication
and the generation of a QR code for two-factor authentication (2FA) using Google
Authenticator. Below is a basic outline of what the `Qr_code.php` file might look
like to display the generated QR code to the user.

### Qr_code.php

```php
<?php
session_start();

// Vérifiez si l'utilisateur est connecté


if (!isset($_SESSION['user_id'])) {
header('Location: load.php?redirect=Login.php');
exit();
}

// Vérifiez si l'URL du code QR est définie dans la session


if (!isset($_SESSION['qr_code_url'])) {
header('Location: verif_email.php'); // Redirigez si le QR code n'est pas
disponible
exit();
}

$qrCodeUrl = $_SESSION['qr_code_url'];
$email = $_SESSION['email']; // Récupérer l'email de la session

// Affichage des notifications de session


if (isset($_SESSION['toast_message'])) {
displayToast($_SESSION['toast_message'], $_SESSION['toast_type']);
unset($_SESSION['toast_message'], $_SESSION['toast_type']); // Réinitialiser
les messages
}

// Fonction pour afficher les notifications


function displayToast($message, $type = 'success') {
$bgColor = $type === 'error' ? 'bg-red-500' : ($type === 'warning' ? 'bg-
orange-500' : 'bg-green-500');
echo "
<div class='toast flex items-center justify-center p-4 $bgColor text-white
rounded shadow-lg max-w-xs fixed top-4 right-4 z-50'>
<span>$message</span>
<button class='ml-4 bg-red-500 text-white py-1 px-2 rounded'
onclick='this.parentElement.remove()'>X</button>
</div>
";
}
?>

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QR Code</title>
<link rel="stylesheet" href="path/to/your/styles.css"> <!-- Lien vers votre
fichier CSS -->
</head>
<body>
<div class="container">
<h1>Scan le QR Code</h1>
<p>Utilisez l'application Google Authenticator pour scanner le code QR ci-
dessous :</p>
<img src="<?php echo htmlspecialchars($qrCodeUrl); ?>" alt="QR Code" />
<p>Ou entrez le code secret : <strong><?php echo
htmlspecialchars($user['google_auth_secret']); ?></strong></p>
<a href="logout.php" class="btn">Déconnexion</a>
</div>
</body>
</html>
```

### Explanation:
1. **Session Management**: The script checks if the user is logged in by verifying
the `user_id` in the session. If not, it redirects to the login page.

2. **QR Code URL**: It checks if the QR code URL is set in the session. If not, it
redirects the user back to the email verification page.

3. **Display Toast Notifications**: If there are any toast messages stored in the
session, it displays them and then clears them from the session.

4. **HTML Structure**: The HTML includes a title, a message prompting the user to
scan the QR code, and an image tag that displays the QR code. It also provides a
logout button.

5. **Security**: The `htmlspecialchars()` function is used to prevent XSS attacks


by escaping special characters in the output.

Make sure to adjust the paths and styles according to your application's structure.

You might also like