197 lines
8.0 KiB
PHP
197 lines
8.0 KiB
PHP
<?php
|
|
/**
|
|
* Verifica Email
|
|
*
|
|
* Conferma l'indirizzo email dell'utente tramite token
|
|
*/
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
session_start();
|
|
|
|
$success = false;
|
|
$error = '';
|
|
$email = '';
|
|
|
|
// Verifica token
|
|
if (isset($_GET['token']) && !empty($_GET['token'])) {
|
|
$token = sanitize_input($_GET['token']);
|
|
|
|
try {
|
|
$pdo = get_db_connection();
|
|
|
|
// Trova utente con questo token
|
|
$stmt = $pdo->prepare("
|
|
SELECT id, email, first_name, email_token_expires, email_verified
|
|
FROM users
|
|
WHERE email_token = ?
|
|
AND deleted_at IS NULL
|
|
");
|
|
$stmt->execute([$token]);
|
|
$user = $stmt->fetch();
|
|
|
|
if (!$user) {
|
|
$error = 'Token non valido o già utilizzato.';
|
|
} elseif ($user['email_verified']) {
|
|
$error = 'Questo account è già stato verificato. Puoi effettuare il login.';
|
|
$email = $user['email'];
|
|
} elseif (strtotime($user['email_token_expires']) < time()) {
|
|
$error = 'Il token è scaduto. Richiedi un nuovo link di verifica dalla pagina di login.';
|
|
$email = $user['email'];
|
|
} else {
|
|
// Token valido - verifica email
|
|
$stmt = $pdo->prepare("
|
|
UPDATE users
|
|
SET email_verified = TRUE,
|
|
email_token = NULL,
|
|
email_token_expires = NULL,
|
|
updated_at = NOW()
|
|
WHERE id = ?
|
|
");
|
|
$stmt->execute([$user['id']]);
|
|
|
|
// Log attività
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO activity_log (user_id, action, description, ip_address, user_agent, created_at)
|
|
VALUES (?, 'email_verified', 'Email verificata con successo', ?, ?, NOW())
|
|
");
|
|
$stmt->execute([
|
|
$user['id'],
|
|
$_SERVER['REMOTE_ADDR'] ?? null,
|
|
$_SERVER['HTTP_USER_AGENT'] ?? null
|
|
]);
|
|
|
|
// Invia email di benvenuto
|
|
$subject = "Benvenuto su " . SITE_NAME . "!";
|
|
$body = "
|
|
<html>
|
|
<head>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
|
|
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
|
|
.header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; }
|
|
.content { background: #f9f9f9; padding: 30px; border-radius: 0 0 8px 8px; }
|
|
.button { display: inline-block; padding: 12px 30px; background: #667eea; color: white; text-decoration: none; border-radius: 5px; margin: 20px 0; }
|
|
.footer { text-align: center; color: #999; font-size: 12px; margin-top: 20px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class='container'>
|
|
<div class='header'>
|
|
<h1>✅ Account Attivato!</h1>
|
|
</div>
|
|
<div class='content'>
|
|
<p>Ciao <strong>" . htmlspecialchars($user['first_name']) . "</strong>,</p>
|
|
<p>🎉 Il tuo account è stato verificato con successo!</p>
|
|
<p>Ora puoi accedere alla piattaforma e iniziare a esplorare il nostro catalogo di lezioni di Pilates.</p>
|
|
<div style='text-align: center;'>
|
|
<a href='" . SITE_URL . "/login.php' class='button'>Accedi Ora</a>
|
|
</div>
|
|
<p><strong>Cosa puoi fare ora:</strong></p>
|
|
<ul>
|
|
<li>🎥 Guarda le lezioni demo gratuite</li>
|
|
<li>📚 Esplora il catalogo completo</li>
|
|
<li>🛒 Acquista le lezioni che ti interessano</li>
|
|
<li>👤 Personalizza il tuo profilo</li>
|
|
</ul>
|
|
<p>Se hai domande o hai bisogno di assistenza, non esitare a contattarci.</p>
|
|
<p>Buon allenamento!<br>Il team di " . SITE_NAME . "</p>
|
|
</div>
|
|
<div class='footer'>
|
|
<p>Questa è una email automatica, per favore non rispondere a questo messaggio.</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
";
|
|
|
|
send_email($user['email'], $subject, $body);
|
|
|
|
$success = true;
|
|
$email = $user['email'];
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
$error = 'Errore durante la verifica. Riprova più tardi.';
|
|
error_log("Email verification error: " . $e->getMessage());
|
|
}
|
|
} else {
|
|
$error = 'Token mancante. Controlla il link nell\'email di verifica.';
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Verifica Email - <?php echo SITE_NAME; ?></title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
<header class="header">
|
|
<div class="container">
|
|
<div class="header-content">
|
|
<h1 class="logo">
|
|
<a href="index.php" style="color: inherit; text-decoration: none;"><?php echo SITE_NAME; ?></a>
|
|
</h1>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container" style="max-width: 600px; margin: 50px auto;">
|
|
<div class="card">
|
|
<h2 class="section-title" style="text-align: center;">
|
|
<?php echo $success ? '✅ Email Verificata!' : '❌ Verifica Fallita'; ?>
|
|
</h2>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success">
|
|
<p style="font-size: 16px; margin-bottom: 15px;">
|
|
Il tuo account è stato attivato con successo!
|
|
</p>
|
|
<p>
|
|
Email verificata: <strong><?php echo htmlspecialchars($email); ?></strong>
|
|
</p>
|
|
<p style="margin-top: 20px;">
|
|
Ora puoi accedere alla piattaforma e iniziare il tuo percorso di Pilates!
|
|
</p>
|
|
<div style="text-align: center; margin-top: 30px;">
|
|
<a href="login.php" class="btn btn-primary btn-large">
|
|
🔐 Vai al Login
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="alert alert-error">
|
|
<p style="font-size: 16px; margin-bottom: 15px;">
|
|
<?php echo htmlspecialchars($error); ?>
|
|
</p>
|
|
<?php if ($email): ?>
|
|
<p style="margin-top: 20px;">
|
|
Puoi richiedere un nuovo link di verifica dalla pagina di login.
|
|
</p>
|
|
<?php endif; ?>
|
|
<div style="text-align: center; margin-top: 30px;">
|
|
<a href="login.php" class="btn btn-primary">
|
|
← Torna al Login
|
|
</a>
|
|
<?php if ($email): ?>
|
|
<a href="resend_verification.php?email=<?php echo urlencode($email); ?>" class="btn btn-secondary" style="margin-left: 10px;">
|
|
📧 Invia Nuovo Link
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="footer">
|
|
<div class="container">
|
|
<p>© <?php echo date('Y'); ?> <?php echo SITE_NAME; ?>. Tutti i diritti riservati.</p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|