245 lines
8.6 KiB
PHP
245 lines
8.6 KiB
PHP
<?php
|
|
/**
|
|
* Login Page
|
|
* Telvero Talpa Planning System
|
|
*/
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Dotenv\Dotenv;
|
|
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
|
|
$dotenv->load();
|
|
|
|
require_once __DIR__ . '/auth_functions.php';
|
|
|
|
// If already logged in, redirect to dashboard
|
|
if (isLoggedIn()) {
|
|
header("Location: /index.php");
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
$redirect = $_GET['redirect'] ?? 'index.php';
|
|
$reason = $_GET['reason'] ?? '';
|
|
|
|
// Handle login form submission
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($username) || empty($password)) {
|
|
$error = 'Vul je gebruikersnaam en wachtwoord in.';
|
|
} else {
|
|
$result = attemptLogin($username, $password);
|
|
|
|
if ($result['success']) {
|
|
// Redirect to original page or dashboard
|
|
$redirectUrl = '/' . ltrim(urldecode($redirect), '/');
|
|
// Security: only allow relative redirects
|
|
if (strpos($redirectUrl, '//') !== false || strpos($redirectUrl, 'http') === 0) {
|
|
$redirectUrl = '/index.php';
|
|
}
|
|
header("Location: $redirectUrl");
|
|
exit;
|
|
} else {
|
|
$error = $result['error'];
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="nl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Inloggen - Telvero Talpa</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
|
|
<style>
|
|
body {
|
|
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.login-wrapper {
|
|
width: 100%;
|
|
max-width: 420px;
|
|
padding: 1rem;
|
|
}
|
|
.login-card {
|
|
border: none;
|
|
border-radius: 16px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
|
|
}
|
|
.login-header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
border-radius: 16px 16px 0 0;
|
|
padding: 2rem;
|
|
text-align: center;
|
|
color: white;
|
|
}
|
|
.login-header .brand-icon {
|
|
font-size: 3rem;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.login-header h1 {
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
.login-header p {
|
|
font-size: 0.875rem;
|
|
opacity: 0.85;
|
|
margin-bottom: 0;
|
|
}
|
|
.login-body {
|
|
padding: 2rem;
|
|
}
|
|
.form-control:focus {
|
|
border-color: #667eea;
|
|
box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
|
|
}
|
|
.btn-login {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
border: none;
|
|
padding: 0.75rem;
|
|
font-weight: 600;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
.btn-login:hover {
|
|
background: linear-gradient(135deg, #5a6fd6 0%, #6a3f96 100%);
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
|
}
|
|
.input-group-text {
|
|
background-color: #f8f9fa;
|
|
border-right: none;
|
|
}
|
|
.input-group .form-control {
|
|
border-left: none;
|
|
}
|
|
.input-group .form-control:focus {
|
|
border-left: none;
|
|
}
|
|
.login-footer {
|
|
text-align: center;
|
|
padding: 1rem 2rem 1.5rem;
|
|
border-top: 1px solid #f0f0f0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-wrapper">
|
|
<div class="card login-card">
|
|
<!-- Header -->
|
|
<div class="login-header">
|
|
<div class="brand-icon">
|
|
<i class="bi bi-tv"></i>
|
|
</div>
|
|
<h1>Telvero Talpa</h1>
|
|
<p>Planning System</p>
|
|
</div>
|
|
|
|
<!-- Body -->
|
|
<div class="login-body">
|
|
<?php if ($reason === 'timeout'): ?>
|
|
<div class="alert alert-warning alert-dismissible fade show" role="alert">
|
|
<i class="bi bi-clock"></i>
|
|
Je sessie is verlopen. Log opnieuw in.
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($error)): ?>
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<i class="bi bi-exclamation-triangle"></i>
|
|
<?= htmlspecialchars($error) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" autocomplete="on">
|
|
<input type="hidden" name="redirect" value="<?= htmlspecialchars($redirect) ?>">
|
|
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label fw-semibold">
|
|
Gebruikersnaam of Email
|
|
</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text">
|
|
<i class="bi bi-person text-muted"></i>
|
|
</span>
|
|
<input type="text"
|
|
id="username"
|
|
name="username"
|
|
class="form-control"
|
|
placeholder="Gebruikersnaam of email"
|
|
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"
|
|
required
|
|
autofocus
|
|
autocomplete="username">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<label for="password" class="form-label fw-semibold">
|
|
Wachtwoord
|
|
</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text">
|
|
<i class="bi bi-lock text-muted"></i>
|
|
</span>
|
|
<input type="password"
|
|
id="password"
|
|
name="password"
|
|
class="form-control"
|
|
placeholder="Wachtwoord"
|
|
required
|
|
autocomplete="current-password">
|
|
<button class="btn btn-outline-secondary"
|
|
type="button"
|
|
id="togglePassword"
|
|
title="Wachtwoord tonen/verbergen">
|
|
<i class="bi bi-eye" id="toggleIcon"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-login w-100">
|
|
<i class="bi bi-box-arrow-in-right me-2"></i>
|
|
Inloggen
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Footer -->
|
|
<div class="login-footer">
|
|
<small class="text-muted">
|
|
<i class="bi bi-shield-check text-success"></i>
|
|
Beveiligde verbinding • Telvero © <?= date('Y') ?>
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
// Toggle password visibility
|
|
document.getElementById('togglePassword').addEventListener('click', function() {
|
|
const passwordInput = document.getElementById('password');
|
|
const toggleIcon = document.getElementById('toggleIcon');
|
|
|
|
if (passwordInput.type === 'password') {
|
|
passwordInput.type = 'text';
|
|
toggleIcon.className = 'bi bi-eye-slash';
|
|
} else {
|
|
passwordInput.type = 'password';
|
|
toggleIcon.className = 'bi bi-eye';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|