add user confirmation
This commit is contained in:
207
resend_verification.php
Normal file
207
resend_verification.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* Re-Invio Email di Verifica
|
||||
*
|
||||
* Permette agli utenti di richiedere un nuovo link di verifica email
|
||||
*/
|
||||
|
||||
require_once 'includes/config.php';
|
||||
require_once 'includes/functions.php';
|
||||
|
||||
session_start();
|
||||
|
||||
$success = false;
|
||||
$error = '';
|
||||
$email = sanitize_input($_GET['email'] ?? '');
|
||||
|
||||
// Processa il form
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = sanitize_input($_POST['email'] ?? '');
|
||||
|
||||
if (empty($email)) {
|
||||
$error = 'Inserisci la tua email';
|
||||
} elseif (!validate_email($email)) {
|
||||
$error = 'Email non valida';
|
||||
} else {
|
||||
try {
|
||||
$pdo = get_db_connection();
|
||||
|
||||
// Trova utente
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT id, first_name, email_verified
|
||||
FROM users
|
||||
WHERE email = ?
|
||||
AND deleted_at IS NULL
|
||||
");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (!$user) {
|
||||
// Per sicurezza, non rivelare se l'email esiste
|
||||
$success = true;
|
||||
} elseif ($user['email_verified']) {
|
||||
$error = 'Questo account è già stato verificato. Puoi effettuare il login.';
|
||||
} else {
|
||||
// Genera nuovo token
|
||||
$email_token = bin2hex(random_bytes(32));
|
||||
$token_expires = date('Y-m-d H:i:s', strtotime('+24 hours'));
|
||||
|
||||
// Aggiorna token
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE users
|
||||
SET email_token = ?,
|
||||
email_token_expires = ?,
|
||||
updated_at = NOW()
|
||||
WHERE id = ?
|
||||
");
|
||||
$stmt->execute([$email_token, $token_expires, $user['id']]);
|
||||
|
||||
// Log attività
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO activity_log (user_id, action, description, ip_address, user_agent, created_at)
|
||||
VALUES (?, 'resend_verification', 'Richiesto nuovo link verifica email', ?, ?, NOW())
|
||||
");
|
||||
$stmt->execute([
|
||||
$user['id'],
|
||||
$_SERVER['REMOTE_ADDR'] ?? null,
|
||||
$_SERVER['HTTP_USER_AGENT'] ?? null
|
||||
]);
|
||||
|
||||
// Invia email
|
||||
$verify_url = SITE_URL . "/verify_email.php?token=" . $email_token;
|
||||
$subject = "Conferma il tuo account 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; }
|
||||
.warning { background: #fff3cd; border-left: 4px solid #ffc107; padding: 15px; margin: 20px 0; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='container'>
|
||||
<div class='header'>
|
||||
<h1>Nuovo Link di Verifica</h1>
|
||||
</div>
|
||||
<div class='content'>
|
||||
<p>Ciao <strong>" . htmlspecialchars($user['first_name']) . "</strong>,</p>
|
||||
<p>Hai richiesto un nuovo link per verificare il tuo account su " . SITE_NAME . ".</p>
|
||||
<p>Per completare la registrazione e attivare il tuo account, clicca sul pulsante qui sotto:</p>
|
||||
<div style='text-align: center;'>
|
||||
<a href='" . $verify_url . "' class='button'>✅ Conferma Email</a>
|
||||
</div>
|
||||
<p style='font-size: 14px; color: #666;'>Oppure copia e incolla questo link nel tuo browser:<br>
|
||||
<a href='" . $verify_url . "'>" . $verify_url . "</a></p>
|
||||
<div class='warning'>
|
||||
<strong>⏰ Importante:</strong> Questo link è valido per 24 ore. Questo nuovo link sostituisce quello precedente.
|
||||
</div>
|
||||
<p>Se non hai richiesto questo link, ignora questa email e il tuo account rimarrà non verificato.</p>
|
||||
<p>A presto!<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($email, $subject, $body);
|
||||
$success = true;
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Errore durante l\'invio. Riprova più tardi.';
|
||||
error_log("Resend verification error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Re-Invio 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: 500px; margin: 50px auto;">
|
||||
<div class="card">
|
||||
<h2 class="section-title" style="text-align: center;">📧 Re-Invio Email di Verifica</h2>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success">
|
||||
<h3 style="margin-top: 0;">✅ Email Inviata!</h3>
|
||||
<p>Se l'email è registrata nel nostro sistema, riceverai un nuovo link di verifica.</p>
|
||||
<p class="text-muted" style="font-size: 14px; margin-top: 15px;">
|
||||
Controlla la tua casella email (e la cartella spam). Il link è valido per 24 ore.
|
||||
</p>
|
||||
<div style="text-align: center; margin-top: 25px;">
|
||||
<a href="login.php" class="btn btn-primary">
|
||||
← Torna al Login
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p class="text-center text-muted" style="margin-bottom: 20px;">
|
||||
Inserisci la tua email per ricevere un nuovo link di verifica
|
||||
</p>
|
||||
|
||||
<form method="POST" action="">
|
||||
<div class="form-group">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
class="form-control"
|
||||
value="<?php echo htmlspecialchars($email); ?>"
|
||||
required
|
||||
autofocus
|
||||
placeholder="tua-email@esempio.com"
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-large" style="width: 100%;">
|
||||
📧 Invia Nuovo Link
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="text-center mt-2">
|
||||
<p class="text-muted">
|
||||
<a href="login.php">← Torna al Login</a>
|
||||
</p>
|
||||
</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>
|
||||
Reference in New Issue
Block a user