tombola / login.php
Alcalata31's picture
Update login.php
7d7e105 verified
Raw
History Blame Contribute Delete
1.97 kB
<?php
require_once 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = sanitizeInput($_POST['email']);
$password = sanitizeInput($_POST['password']);
// Get user from database
$stmt = $db->prepare("SELECT user_id, password, is_verified FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user) {
// Verify password
if (password_verify($password, $user['password'])) {
// Check if account is verified
if (!$user['is_verified']) {
$error = "Please verify your email first";
} else {
// Set session and redirect
$_SESSION['user_id'] = $user['user_id'];
redirect('dashboard.php');
}
} else {
$error = "Invalid email or password";
}
} else {
$error = "Invalid email or password";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login - Monthly Tombola</title>
<!-- Include your CSS and JS files -->
</head>
<body>
<div class="container">
<h1>Login</h1>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form method="post">
<div class="form-group">
<label>Email:</label>
<input type="email" name="email" required class="form-control">
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" name="password" required class="form-control">
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
<p>Don't have an account? <a href="register.php">Register here</a></p>
<p><a href="forgot-password.php">Forgot password?</a></p>
</div>
</body>
</html>