Add register.php
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
|||||||
|
<?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>
|
||||||
Reference in New Issue
Block a user