128 lines
3.3 KiB
PHP
128 lines
3.3 KiB
PHP
<?php
|
|
include_once(__DIR__ . '/controller/UserController.php');
|
|
include_once(__DIR__ . '/controller/DataController.php');
|
|
include_once(__DIR__ . '/controller/RightsController.php');
|
|
include_once(__DIR__ . '/controller/RoutesController.php');
|
|
|
|
ob_start();
|
|
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'domain' => '',
|
|
'secure' => false,
|
|
'httponly' => true,
|
|
'samesite' => 'Lax'
|
|
]);
|
|
session_start();
|
|
|
|
$error = null;
|
|
|
|
function loginAfterRegister($username): void
|
|
{
|
|
$_SESSION['user_logged_in'] = true;
|
|
$_SESSION['username'] = $username;
|
|
$_SESSION['is_admin'] = false;
|
|
$_SESSION['is_superuser'] = false;
|
|
|
|
session_write_close();
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$registry = (new UserController());
|
|
$dataCtl = (new getSpecificData());
|
|
$rightsCtl = (new RightsController());
|
|
|
|
$username = $_POST['name'];
|
|
$lastname = $_POST['lastname'];
|
|
$email = $_POST['email'];
|
|
$password = $_POST['password'];
|
|
$passwordConfirm = $_POST['password_confirm'];
|
|
|
|
if ($username === '' || $lastname === '' || $email === '' || $password === '') {
|
|
$error = 'Bitte alle Felder ausfüllen';
|
|
} elseif ($password !== $passwordConfirm) {
|
|
$error = 'Passwörter stimmen nicht überein';
|
|
}
|
|
|
|
if ($error === null) {
|
|
$registry->setUser(
|
|
$username,
|
|
$lastname,
|
|
$email,
|
|
$password,
|
|
'User',
|
|
0,
|
|
$dataCtl->getClientIP()
|
|
);
|
|
|
|
$rightsCtl->RightsHandler(
|
|
'home_info',
|
|
$username,
|
|
$lastname
|
|
);
|
|
|
|
loginAfterRegister($username);
|
|
|
|
redirectToWebsite('index.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Registrieren</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="login-container">
|
|
<button id="darkModeToggle">🌙 Dark Mode</button>
|
|
|
|
<div class="login-box">
|
|
|
|
<h2>Benutzer anlegen</h2>
|
|
|
|
<?php if ($error): ?>
|
|
<p class="login-error"><?= htmlspecialchars($error) ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" class="register-form">
|
|
<input type="text" name="name" placeholder="Vorname" required>
|
|
<input type="text" name="lastname" placeholder="Nachname" required>
|
|
<input type="email" name="email" placeholder="Email" required>
|
|
<input type="password" name="password" placeholder="Passwort" required>
|
|
<input type="password" name="password_confirm" placeholder="Passwort wiederholen" required>
|
|
<button type="submit">Registrieren</button>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const toggle = document.getElementById('darkModeToggle');
|
|
|
|
if (localStorage.getItem('darkMode') === 'enabled') {
|
|
document.body.classList.add('dark-mode');
|
|
}
|
|
|
|
toggle.addEventListener('click', () => {
|
|
document.body.classList.toggle('dark-mode');
|
|
|
|
if (document.body.classList.contains('dark-mode')) {
|
|
localStorage.setItem('darkMode', 'enabled');
|
|
} else {
|
|
localStorage.setItem('darkMode', 'disabled');
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|