38527-vm/auth/login.php
Flatlogic Bot 4883125cda v2
2026-02-15 10:30:17 +00:00

70 lines
3.0 KiB
PHP

<?php
require_once __DIR__ . '/session.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if ($email && $password) {
$stmt = db()->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password_hash'])) {
$_SESSION['user_id'] = $user['id'];
header('Location: ../index.php');
exit;
} else {
$error = "Invalid email or password.";
}
} else {
$error = "Please fill all fields.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login | Discord Clone</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/discord.css">
<style>
body { background-color: #313338; display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-card { background-color: #2b2d31; padding: 32px; border-radius: 8px; width: 100%; max-width: 480px; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.form-label { color: #b5bac1; font-size: 12px; font-weight: bold; text-transform: uppercase; }
.form-control { background-color: #1e1f22; border: none; color: #dbdee1; padding: 10px; }
.form-control:focus { background-color: #1e1f22; color: #dbdee1; box-shadow: none; }
.btn-blurple { background-color: #5865f2; color: white; width: 100%; font-weight: bold; margin-top: 20px; }
.btn-blurple:hover { background-color: #4752c4; color: white; }
.auth-footer { color: #949ba4; font-size: 14px; margin-top: 10px; }
.auth-footer a { color: #00a8fc; text-decoration: none; }
</style>
</head>
<body>
<div class="auth-card">
<h3 class="text-center mb-1">Welcome back!</h3>
<p class="text-center mb-4" style="color: #b5bac1;">We're so excited to see you again!</p>
<?php if($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label">Email or Phone Number</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<a href="#" style="color: #00a8fc; font-size: 14px; text-decoration: none;">Forgot your password?</a>
<button type="submit" class="btn btn-blurple">Log In</button>
<div class="auth-footer">
Need an account? <a href="register.php">Register</a>
</div>
</form>
</div>
</body>
</html>