101 lines
4.2 KiB
PHP
101 lines
4.2 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$pageTitle = "Login";
|
|
$pageDescription = "Accedi alla piattaforma per prenotare o offrire servizi.";
|
|
|
|
$error = null;
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$email = trim($_POST['email'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($email) || empty($password)) {
|
|
$error = "Per favore, inserisci email e password.";
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
|
|
$stmt->execute([$email]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
// Password is correct, start session
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_type'] = $user['user_type'];
|
|
$_SESSION['user_name'] = $user['first_name'];
|
|
|
|
// Redirect to a logged-in page (e.g., dashboard)
|
|
header("Location: index.php");
|
|
exit;
|
|
} else {
|
|
$error = "Email o password non validi.";
|
|
}
|
|
} catch (PDOException $e) {
|
|
$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-5">
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body p-4">
|
|
<h1 class="card-title text-center mb-4 h2">Accedi</h1>
|
|
<p class="text-center text-muted mb-4">Bentornato! Accedi per gestire i tuoi servizi.</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger" role="alert">
|
|
<?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="login.php" method="POST" novalidate>
|
|
<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-4">
|
|
<label for="password" class="form-label">Password</label>
|
|
<input type="password" class="form-control" id="password" name="password" required>
|
|
</div>
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary btn-lg">Login</button>
|
|
</div>
|
|
</form>
|
|
<div class="text-center mt-4">
|
|
<p class="mb-0">Non hai un account? <a href="register.php">Registrati ora</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>
|