servnest/public/auth/register.php

75 lines
2.4 KiB
PHP
Raw Normal View History

<?php require "../../common/html.php"; ?>
2021-01-22 21:58:46 +01:00
2022-06-06 23:14:50 +02:00
<p>Déjà un compte ? <a class="auth" href="login">Se connecter</a></p>
<?php
2021-01-22 21:58:46 +01:00
if (isset($_POST['username']) AND isset($_POST['password'])) {
2021-01-22 21:58:46 +01:00
checkPasswordFormat($_POST['password']);
2021-01-22 21:58:46 +01:00
checkUsernameFormat($_POST['username']);
2021-01-25 13:39:31 +01:00
2022-05-21 19:41:46 +02:00
$userExist = userExist($_POST['username']);
if ($userExist === false) {
2021-01-22 21:58:46 +01:00
// Setup SFTP directory
umask(0002);
2022-05-21 19:41:46 +02:00
if (mkdir(CONF['ht']['ht_path'] . "/" . $_POST['username'], 0775) !== true)
serverError("Can't create user directory.");
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['chgrp_path'] . " " . CONF['ht']['sftpgo_group'] . " " . CONF['ht']['ht_path'] . "/" . $_POST['username'] . " --no-dereference", $stdout, $code);
if ($code !== 0)
serverError("Can't change user directory group.");
2022-04-18 16:05:00 +02:00
$password = hashPassword($_POST['password']);
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
$db = new PDO('sqlite:' . DB_PATH);
2021-01-22 21:58:46 +01:00
$stmt = $db->prepare("INSERT INTO users(username, password, registration_date) VALUES(:username, :password, :registration_date)");
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
$time = date("Y-m-d H:i:s");
2021-01-22 21:58:46 +01:00
2022-05-21 19:41:46 +02:00
$stmt->bindParam(':username', $_POST['username']);
2022-04-18 16:05:00 +02:00
$stmt->bindParam(':password', $password);
$stmt->bindParam(':registration_date', $time);
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
$stmt->execute();
2021-01-22 21:58:46 +01:00
2022-05-21 19:41:46 +02:00
$_SESSION['username'] = $_POST['username'];
2022-05-20 01:08:40 +02:00
header('Location: ' . CONF['common']['prefix'] . '/');
2022-04-18 16:05:00 +02:00
exit;
}
}
2021-01-22 21:58:46 +01:00
?>
<form method="post">
2022-04-18 16:05:00 +02:00
2022-05-31 23:28:32 +02:00
<details>
<summary><label for="username">Identifiant</label></summary>
Uniquement composé de lettres minuscules.
</details>
<input id="username" minlength="4" maxlength="32" pattern="<?= USERNAME_REGEX ?>" required="" name="username" type="text" placeholder="lain"><span></span><br>
<?php
if (isset($userExist) AND $userExist === true) {
echo "<br>Cet identifiant est déjà utilisé. Choisissez-en un autre.";
}
?>
<details>
<summary><label for="password">Clé de passe</label></summary>
<p>Une clé de passe sécurisée est trop compliquée à deviner pour une attaque qui testerais automatiquement plein de clés de passe tout en connaissant d'autres informations et secrets sur vous.</p>
<p>Minimum 8 caractères si elle contient minuscule, majuscule et chiffre, ou minimum 10 caractères sinon.</p>
</details>
2022-04-18 16:05:00 +02:00
2022-05-31 23:28:32 +02:00
<input autocomplete="new-password" id="password" minlength="8" maxlength="1024" pattern="<?= PASSWORD_REGEX ?>" required="" name="password" type="password" placeholder="************"><span title="Le format nest pas valide"></span><br>
2022-04-18 16:05:00 +02:00
<input type="submit">
</form>
<?php closeHTML(); ?>