Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/submissions/projekt-matkort-handler/
.github/
add_logs.php
admin/
api/
card_balance.php
classes/
config/
food_logs.php
forgot_password.php
includes/
index.php
insert_restaurants.php
install.php
login.php
logout.php
public/
register.php
reset_password.php
verify.php
login.php
78 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include_once './config/database.php';
include_once './classes/User.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = htmlspecialchars(trim($_POST['email']));
$password = htmlspecialchars($_POST['password']);
try {
User::login($pdo, $email, $password);
if (isset($_SESSION['is_admin']) && $_SESSION['is_admin'] === true) {
header("Location: admin/admin_dashboard.php");
} else {
header("Location: index.php");
}
exit();
} catch (Exception $e) {
$error = $e->getMessage();
}
}
$page_title = 'Logga in';
require_once './includes/header.php';
?>
<div class="auth-container">
<div class="auth-box">
<h1>Logga in</h1>
<?php if (!empty($error)): ?>
<div class="error-message">
<?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<form method="POST" action="login.php">
<div class="form-group">
<label for="email">Epost:</label>
<input
type="text"
id="email"
name="email"
value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>"
required
>
</div>
<div class="form-group">
<label for="password">Lösenord:</label>
<input
type="password"
id="password"
name="password"
required
>
</div>
<p class="forgot-link" style="text-align: left; margin-bottom: 15px; font-size:14px;">
<a href="./forgot_password.php">Glömt lösenord?</a>
</p>
<button type="submit" class="btn btn-primary">Logga in</button>
</form>
<p class="register-link">
Inget konto? <a href="./register.php">Registrera dig här</a>
</p>
</div>
</div>
<?php require_once './includes/footer.php'; ?>