Files
pilates-platform/register.php
Francesco Picone e7ea7dbd3b fix video
2025-12-09 16:46:59 +01:00

238 lines
9.7 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 {
// Crea il nuovo utente
$user_id = create_user($email, $password, $first_name, $last_name);
if ($user_id) {
$success = true;
// 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>Benvenuto su " . SITE_NAME . "!</h1>
</div>
<div class='content'>
<p>Ciao <strong>" . htmlspecialchars($first_name) . "</strong>,</p>
<p>Grazie per esserti registrato sulla nostra piattaforma! Il tuo account è stato creato con successo.</p>
<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>Ora puoi accedere al catalogo delle nostre lezioni e iniziare il tuo percorso di Pilates!</p>
<div style='text-align: center;'>
<a href='" . SITE_URL . "/user/dashboard.php' class='button'>Vai alla Dashboard</a>
</div>
<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($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', ?, ?, NOW())
");
$stmt->execute([
$user_id,
$_SERVER['REMOTE_ADDR'] ?? null,
$_SERVER['HTTP_USER_AGENT'] ?? null
]);
// Login automatico dopo registrazione
login_user($user_id, false);
// Reindirizza dopo 2 secondi
header("refresh:2;url=user/dashboard.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): ?>
<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>