89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
session_start();
|
|
|
|
if (isset($_SESSION['user_id'])) {
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$email = $_POST['email'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($email) || empty($password)) {
|
|
$error = 'Please fill in all fields.';
|
|
} 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'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Invalid email or password.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = 'Database error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - Aperture</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<header class="app-header">
|
|
<div class="container">
|
|
<div class="header-content">
|
|
<a href="index.php" class="logo">Aperture</a>
|
|
<nav class="main-nav">
|
|
<a href="index.php#features">Features</a>
|
|
<a href="index.php#contact">Contact</a>
|
|
<a href="register.php">Register</a>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container page-section">
|
|
<section class="auth-form">
|
|
<h2>Login</h2>
|
|
<?php if ($error): ?>
|
|
<div class="form-message error-message"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
<form action="login.php" method="POST">
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" name="email" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Login</button>
|
|
</form>
|
|
</section>
|
|
</main>
|
|
|
|
<footer class="app-footer">
|
|
<div class="container">
|
|
<p>© <?php echo date('Y'); ?> Aperture. All rights reserved. | <a href="privacy.php">Privacy Policy</a></p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|