108 lines
1.7 KiB
PHP
108 lines
1.7 KiB
PHP
<?php
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/jsondb.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$username = sanitize($_POST['username']);
|
|
$password = $_POST['password'];
|
|
|
|
if (
|
|
strlen($username) < 3 ||
|
|
strlen($password) < 6
|
|
) {
|
|
$error = 'Ongeldige invoer.';
|
|
} else {
|
|
|
|
$folder = userPath($username);
|
|
|
|
if (is_dir($folder)) {
|
|
|
|
$error = 'Gebruiker bestaat al.';
|
|
|
|
} else {
|
|
|
|
mkdir($folder, 0775, true);
|
|
|
|
JsonDB::write(
|
|
$folder . '/user.json',
|
|
[
|
|
'username' => $username,
|
|
'password' => password_hash(
|
|
$password,
|
|
PASSWORD_DEFAULT
|
|
),
|
|
'created' => date('c')
|
|
]
|
|
);
|
|
|
|
mkdir(
|
|
$folder . '/languages',
|
|
0775,
|
|
true
|
|
);
|
|
|
|
mkdir(
|
|
$folder . '/progress',
|
|
0775,
|
|
true
|
|
);
|
|
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Registreren</title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<div class="card">
|
|
|
|
<h1>Registreren</h1>
|
|
|
|
<?php if ($error): ?>
|
|
<p><?= $error ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
|
|
<input
|
|
name="username"
|
|
placeholder="Gebruikersnaam"
|
|
required>
|
|
|
|
<input
|
|
type="password"
|
|
name="password"
|
|
placeholder="Wachtwoord"
|
|
required>
|
|
|
|
<button type="submit">
|
|
Account aanmaken
|
|
</button>
|
|
|
|
</form>
|
|
|
|
<p>
|
|
<a href="login.php">Inloggen</a>
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|