258 lines
11 KiB
PHP
258 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Pagina di Registrazione
|
|
*
|
|
* Permette ai nuovi utenti di creare un account
|
|
*/
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
session_start();
|
|
|
|
// Se l'utente è già loggato, reindirizza
|
|
if (is_logged_in()) {
|
|
header('Location: user/dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
// Variabili per il form
|
|
$first_name = '';
|
|
$last_name = '';
|
|
$email = '';
|
|
$error = '';
|
|
$success = false;
|
|
|
|
// Processa il form se inviato
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$first_name = sanitize_input($_POST['first_name'] ?? '');
|
|
$last_name = sanitize_input($_POST['last_name'] ?? '');
|
|
$email = sanitize_input($_POST['email'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
$password_confirm = $_POST['password_confirm'] ?? '';
|
|
|
|
// Validazione
|
|
if (empty($first_name) || empty($last_name) || empty($email) || empty($password)) {
|
|
$error = 'Tutti i campi sono obbligatori';
|
|
} elseif (!validate_email($email)) {
|
|
$error = 'Email non valida';
|
|
} elseif (strlen($password) < 6) {
|
|
$error = 'La password deve essere di almeno 6 caratteri';
|
|
} elseif ($password !== $password_confirm) {
|
|
$error = 'Le password non corrispondono';
|
|
} else {
|
|
// Verifica se l'email esiste già
|
|
if (get_user_by_email($email)) {
|
|
$error = 'Questa email è già registrata';
|
|
} else {
|
|
// Genera token di verifica email
|
|
$email_token = bin2hex(random_bytes(32));
|
|
$token_expires = date('Y-m-d H:i:s', strtotime('+24 hours'));
|
|
|
|
// Crea il nuovo utente (non verificato)
|
|
$user_id = create_user($email, $password, $first_name, $last_name, false, $email_token, $token_expires);
|
|
|
|
if ($user_id) {
|
|
$success = true;
|
|
|
|
// Invia email di verifica
|
|
$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>Conferma il tuo account</h1>
|
|
</div>
|
|
<div class='content'>
|
|
<p>Ciao <strong>" . htmlspecialchars($first_name) . "</strong>,</p>
|
|
<p>Grazie per esserti registrato su " . SITE_NAME . "!</p>
|
|
<p>Per completare la registrazione e attivare il tuo account, devi confermare il tuo indirizzo email cliccando 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. Dopo questo periodo dovrai richiedere un nuovo link di verifica.
|
|
</div>
|
|
<p><strong>I tuoi dati di accesso:</strong></p>
|
|
<ul>
|
|
<li>Email: " . htmlspecialchars($email) . "</li>
|
|
<li>Password: quella che hai scelto durante la registrazione</li>
|
|
</ul>
|
|
<p>Una volta verificata la tua email, potrai accedere al catalogo delle nostre lezioni e iniziare il tuo percorso di Pilates!</p>
|
|
<p>Se non hai richiesto questa registrazione, ignora questa email.</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);
|
|
|
|
// Log attività
|
|
$pdo = get_db_connection();
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO activity_log (user_id, action, description, ip_address, user_agent, created_at)
|
|
VALUES (?, 'register', 'Nuovo utente registrato - in attesa verifica email', ?, ?, NOW())
|
|
");
|
|
$stmt->execute([
|
|
$user_id,
|
|
$_SERVER['REMOTE_ADDR'] ?? null,
|
|
$_SERVER['HTTP_USER_AGENT'] ?? null
|
|
]);
|
|
|
|
// NON fare login automatico - utente deve verificare email prima
|
|
// Reindirizza a pagina di conferma
|
|
header("refresh:3;url=login.php");
|
|
} else {
|
|
$error = 'Errore durante la registrazione. Riprova più tardi.';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Registrazione - Pilates Platform</title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
<div class="container-sm" style="padding-top: 3rem; padding-bottom: 3rem;">
|
|
<div class="card">
|
|
<div class="text-center mb-3">
|
|
<?php if (file_exists('uploads/images/logo.png')): ?>
|
|
<div class="logo">
|
|
<img src="uploads/images/logo.png" alt="Pilates Studio" class="logo-image">
|
|
</div>
|
|
<?php else: ?>
|
|
<h1 class="logo">Pilates Studio</h1>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<h2 class="card-header text-center">Crea un nuovo account</h2>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success">
|
|
<strong>Registrazione completata!</strong> Verrai reindirizzato alla tua area personale...
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?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;">✅ Registrazione completata!</h3>
|
|
<p>Ti abbiamo inviato un'email di verifica a <strong><?php echo htmlspecialchars($email); ?></strong></p>
|
|
<p>Per attivare il tuo account, clicca sul link che troverai nell'email.</p>
|
|
<p class="text-muted" style="font-size: 14px; margin-top: 15px;">
|
|
⚠️ Il link è valido per 24 ore. Se non lo trovi, controlla la cartella spam.
|
|
</p>
|
|
<p style="margin-top: 20px;">Sarai reindirizzato alla pagina di login tra pochi secondi...</p>
|
|
</div>
|
|
<?php elseif (!$success): ?>
|
|
<form method="POST" action="">
|
|
<div class="form-group">
|
|
<label for="first_name" class="form-label">Nome</label>
|
|
<input
|
|
type="text"
|
|
id="first_name"
|
|
name="first_name"
|
|
class="form-control"
|
|
value="<?php echo htmlspecialchars($first_name); ?>"
|
|
required
|
|
autofocus
|
|
>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="last_name" class="form-label">Cognome</label>
|
|
<input
|
|
type="text"
|
|
id="last_name"
|
|
name="last_name"
|
|
class="form-control"
|
|
value="<?php echo htmlspecialchars($last_name); ?>"
|
|
required
|
|
>
|
|
</div>
|
|
|
|
<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
|
|
>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password" class="form-label">Password (minimo 6 caratteri)</label>
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
name="password"
|
|
class="form-control"
|
|
required
|
|
minlength="6"
|
|
>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password_confirm" class="form-label">Conferma Password</label>
|
|
<input
|
|
type="password"
|
|
id="password_confirm"
|
|
name="password_confirm"
|
|
class="form-control"
|
|
required
|
|
minlength="6"
|
|
>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-large" style="width: 100%;">
|
|
Registrati
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<div class="text-center mt-2">
|
|
<p class="text-muted">
|
|
Hai già un account? <a href="login.php"><strong>Accedi</strong></a>
|
|
</p>
|
|
<p class="mt-2">
|
|
<a href="index.php">← Torna alla home</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|