127 lines
6.0 KiB
PHP
127 lines
6.0 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$pageTitle = "Registrazione Cliente";
|
|
$pageDescription = "Crea il tuo account cliente per iniziare a prenotare servizi.";
|
|
|
|
// Registration logic
|
|
$error = null;
|
|
$success = null;
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$name = trim($_POST['name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
$confirm_password = $_POST['confirm_password'] ?? '';
|
|
|
|
// Split name into first and last name
|
|
$name_parts = explode(' ', $name, 2);
|
|
$first_name = $name_parts[0];
|
|
$last_name = $name_parts[1] ?? '';
|
|
|
|
if (empty($first_name) || empty($email) || empty($password)) {
|
|
$error = "Tutti i campi sono obbligatori.";
|
|
} elseif ($password !== $confirm_password) {
|
|
$error = "Le password non coincidono.";
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$error = "L'indirizzo email non è valido.";
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
// Check if email already exists
|
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
|
$stmt->execute([$email]);
|
|
if ($stmt->fetch()) {
|
|
$error = "Un account con questa email esiste già.";
|
|
} else {
|
|
// Hash the password
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
// Insert the new user
|
|
$insert_stmt = $pdo->prepare(
|
|
"INSERT INTO users (first_name, last_name, email, password, user_type) VALUES (?, ?, ?, ?, 'customer')"
|
|
);
|
|
if ($insert_stmt->execute([$first_name, $last_name, $email, $hashed_password])) {
|
|
$success = "Registrazione completata! Ora puoi effettuare il login.";
|
|
} else {
|
|
$error = "Si è verificato un errore durante la registrazione. Riprova.";
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
// In a real app, you would log this error.
|
|
$error = "Errore del database. Riprova più tardi.";
|
|
// error_log($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= htmlspecialchars($pageTitle) ?> - MeToo</title>
|
|
<meta name="description" content="<?= htmlspecialchars($pageDescription) ?>">
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<?php include __DIR__ . '/_header.php'; ?>
|
|
|
|
<main class="container my-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-6">
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body p-4">
|
|
<h1 class="card-title text-center mb-4 h2">Registrati come Cliente</h1>
|
|
<p class="text-center text-muted mb-4">Crea un account per trovare e prenotare servizi in modo facile e veloce.</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger" role="alert"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success" role="alert"><?= htmlspecialchars($success) ?></div>
|
|
<?php else: ?>
|
|
<form action="register_customer.php" method="POST" novalidate>
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Nome Completo</label>
|
|
<input type="text" class="form-control" id="name" name="name" required value="<?= htmlspecialchars($name ?? '') ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Indirizzo Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" required value="<?= htmlspecialchars($email ?? '') ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">Password</label>
|
|
<input type="password" class="form-control" id="password" name="password" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="confirm_password" class="form-label">Conferma Password</label>
|
|
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
|
|
</div>
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary btn-lg">Crea Account</button>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
<div class="text-center mt-4">
|
|
<p class="mb-0">Sei un fornitore? <a href="register_provider.php">Registrati qui</a>.</p>
|
|
<p>Hai già un account? <a href="login.php">Accedi</a>.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php include __DIR__ . '/_footer.php'; ?>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|