Files
pilates-platform/register.php
Francesco Picone 0be59cc836 fix grafica
2025-12-06 17:53:12 +01:00

194 lines
7.0 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;
// 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>