diff --git a/resend_verification.php b/resend_verification.php
new file mode 100644
index 0000000..930ee07
--- /dev/null
+++ b/resend_verification.php
@@ -0,0 +1,207 @@
+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 = "
+
+
+
+
+
+
+
+
+
Ciao " . htmlspecialchars($user['first_name']) . ",
+
Hai richiesto un nuovo link per verificare il tuo account su " . SITE_NAME . ".
+
Per completare la registrazione e attivare il tuo account, clicca sul pulsante qui sotto:
+
+
Oppure copia e incolla questo link nel tuo browser:
+ " . $verify_url . "
+
+ ⏰ Importante: Questo link è valido per 24 ore. Questo nuovo link sostituisce quello precedente.
+
+
Se non hai richiesto questo link, ignora questa email e il tuo account rimarrà non verificato.
+
A presto!
Il team di " . SITE_NAME . "
+
+
+
+
+
+ ";
+
+ 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());
+ }
+ }
+}
+?>
+
+
+
+
+
+
Re-Invio Verifica Email -
+
+
+
+
+
+
+
+
📧 Re-Invio Email di Verifica
+
+
+
+
+
+
+
+
+
+
✅ Email Inviata!
+
Se l'email è registrata nel nostro sistema, riceverai un nuovo link di verifica.
+
+ Controlla la tua casella email (e la cartella spam). Il link è valido per 24 ore.
+
+
+
+
+
+ Inserisci la tua email per ricevere un nuovo link di verifica
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/send_email.py b/send_email.py
index 25e04c9..d0490b6 100644
--- a/send_email.py
+++ b/send_email.py
@@ -2,15 +2,29 @@
"""
Script Python per invio email SMTP
Legge le credenziali da config.php e invia email tramite Gmail
+Log solo in caso di errore
"""
import sys
import json
import re
import smtplib
+import logging
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from pathlib import Path
+from datetime import datetime
+
+# Configura logging solo per errori
+log_file = Path(__file__).parent / 'logs' / 'email_errors.log'
+log_file.parent.mkdir(exist_ok=True)
+
+logging.basicConfig(
+ filename=str(log_file),
+ level=logging.ERROR,
+ format='%(asctime)s - %(levelname)s - %(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S'
+)
def parse_php_config(config_path):
"""Estrae le configurazioni SMTP dal file config.php"""
@@ -86,19 +100,25 @@ def send_email(to_email, subject, html_body, config):
}
except smtplib.SMTPAuthenticationError as e:
+ error_msg = f'Autenticazione SMTP fallita per {to_email}: {str(e)}'
+ logging.error(error_msg)
return {
'success': False,
- 'error': f'Autenticazione SMTP fallita: {str(e)}'
+ 'error': error_msg
}
except smtplib.SMTPException as e:
+ error_msg = f'Errore SMTP invio a {to_email}: {str(e)}'
+ logging.error(error_msg)
return {
'success': False,
- 'error': f'Errore SMTP: {str(e)}'
+ 'error': error_msg
}
except Exception as e:
+ error_msg = f'Errore generico invio a {to_email}: {str(e)}'
+ logging.error(error_msg)
return {
'success': False,
- 'error': f'Errore generico: {str(e)}'
+ 'error': error_msg
}
def main():
@@ -115,9 +135,11 @@ def main():
data = json.loads(sys.argv[1])
if 'to' not in data or 'subject' not in data or 'html' not in data:
+ error = 'Parametri mancanti: to, subject, html sono obbligatori'
+ logging.error(error)
print(json.dumps({
'success': False,
- 'error': 'Parametri mancanti: to, subject, html sono obbligatori'
+ 'error': error
}))
sys.exit(1)
@@ -133,15 +155,19 @@ def main():
sys.exit(0 if result['success'] else 1)
except json.JSONDecodeError as e:
+ error = f'JSON non valido: {str(e)}'
+ logging.error(error)
print(json.dumps({
'success': False,
- 'error': f'JSON non valido: {str(e)}'
+ 'error': error
}))
sys.exit(1)
except Exception as e:
+ error = f'Errore: {str(e)}'
+ logging.error(error)
print(json.dumps({
'success': False,
- 'error': f'Errore: {str(e)}'
+ 'error': error
}))
sys.exit(1)
diff --git a/verify_email.php b/verify_email.php
new file mode 100644
index 0000000..6eea5c2
--- /dev/null
+++ b/verify_email.php
@@ -0,0 +1,196 @@
+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 = "
+
+
+
+
+
+
+
+
+
Ciao " . htmlspecialchars($user['first_name']) . ",
+
🎉 Il tuo account è stato verificato con successo!
+
Ora puoi accedere alla piattaforma e iniziare a esplorare il nostro catalogo di lezioni di Pilates.
+
+
Cosa puoi fare ora:
+
+ - 🎥 Guarda le lezioni demo gratuite
+ - 📚 Esplora il catalogo completo
+ - 🛒 Acquista le lezioni che ti interessano
+ - 👤 Personalizza il tuo profilo
+
+
Se hai domande o hai bisogno di assistenza, non esitare a contattarci.
+
Buon allenamento!
Il team di " . SITE_NAME . "
+
+
+
+
+
+ ";
+
+ 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.';
+}
+?>
+
+
+
+
+
+
Verifica Email -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Il tuo account è stato attivato con successo!
+
+
+ Email verificata:
+
+
+ Ora puoi accedere alla piattaforma e iniziare il tuo percorso di Pilates!
+
+
+
+
+
+
+
+
+
+
+ Puoi richiedere un nuovo link di verifica dalla pagina di login.
+
+
+
+
+
+
+
+
+
+
+