34921-vm/login.php
Flatlogic Bot 42d99a2401 1.6
2025-10-14 13:56:45 +00:00

232 lines
6.8 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
$error = '';
if (isset($_SESSION['user_id'])) {
header("Location: dashboard.php");
exit;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = trim($_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 = :email");
$stmt->execute(['email' => $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 - TAP2SKILL</title>
<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@400;600;700&family=Lato:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #2A9D8F;
--secondary-color: #E9C46A;
--background-color: #F4F4F4;
--surface-color: #FFFFFF;
--text-color: #264653;
--error-color: #e74c3c;
--success-color: #2ecc71;
}
body {
font-family: 'Lato', sans-serif;
margin: 0;
background-color: var(--background-color);
color: var(--text-color);
display: flex;
flex-direction: column;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 24px;
}
header {
background-color: var(--surface-color);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 16px 0;
position: sticky;
top: 0;
z-index: 100;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-family: 'Poppins', sans-serif;
font-size: 24px;
font-weight: 700;
color: var(--primary-color);
text-decoration: none;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
margin-left: 32px;
}
nav ul li a {
text-decoration: none;
color: var(--text-color);
font-weight: 600;
transition: color 0.3s ease;
}
nav ul li a:hover {
color: var(--primary-color);
}
main {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 80px 0;
}
.form-container {
background-color: var(--surface-color);
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
padding: 48px;
width: 100%;
max-width: 480px;
}
.form-title {
font-family: 'Poppins', sans-serif;
font-size: 32px;
text-align: center;
margin-bottom: 32px;
}
form input {
font-family: 'Lato', sans-serif;
padding: 16px;
margin-bottom: 16px;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 16px;
width: 100%;
box-sizing: border-box;
}
form button {
font-family: 'Poppins', sans-serif;
background-color: var(--primary-color);
color: white;
padding: 16px 32px;
border-radius: 8px;
border: none;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
width: 100%;
font-size: 16px;
}
form button:hover {
background-color: #228b80;
}
.alert-message {
color: white;
padding: 16px;
border-radius: 8px;
text-align: center;
margin-bottom: 16px;
}
.alert-message.error {
background-color: var(--error-color);
}
.alert-message.success {
background-color: var(--success-color);
}
.form-footer {
text-align: center;
margin-top: 24px;
}
.form-footer a {
color: var(--primary-color);
text-decoration: none;
font-weight: 600;
}
footer {
background-color: var(--text-color);
color: white;
text-align: center;
padding: 24px 0;
}
</style>
</head>
<body>
<header>
<nav class="container">
<a href="index.php" class="logo">TAP2SKILL</a>
<ul>
<li><a href="index.php#about">About</a></li>
<li><a href="index.php#features">Features</a></li>
<li><a href="index.php#testimonials">Testimonials</a></li>
<li><a href="index.php#contact">Contact</a></li>
<li><a href="register.php">Register</a></li>
</ul>
</nav>
</header>
<main>
<div class="form-container">
<h2 class="form-title">Login</h2>
<?php if (isset($_GET['registered'])): ?>
<div class="alert-message success">Registration successful! Please log in.</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert-message error"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<input type="email" name="email" placeholder="Email Address" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
<div class="form-footer">
<p>Don't have an account? <a href="register.php">Register here</a>.</p>
</div>
</div>
</main>
<footer>
<div class="container">
<p>&copy; 2025 TAP2SKILL. All Rights Reserved.</p>
</div>
</footer>
</body>
</html>