75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php require "../../common/html.php"; ?>
|
|
|
|
<?php
|
|
|
|
if (isset($_POST['username']) AND isset($_POST['password'])) {
|
|
|
|
checkPasswordFormat($_POST['password']);
|
|
|
|
checkUsernameFormat($_POST['username']);
|
|
|
|
$userExist = userExist($_POST['username']);
|
|
|
|
if ($userExist === false) {
|
|
|
|
// Setup SFTP directory
|
|
umask(0002);
|
|
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'], $stdout, $code);
|
|
if ($code !== 0)
|
|
serverError("Can't change user directory group.");
|
|
|
|
$password = hashPassword($_POST['password']);
|
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
|
$stmt = $db->prepare("INSERT INTO users(username, password, registration_date) VALUES(:username, :password, :registration_date)");
|
|
|
|
$time = date("Y-m-d H:i:s");
|
|
|
|
$stmt->bindParam(':username', $_POST['username']);
|
|
$stmt->bindParam(':password', $password);
|
|
$stmt->bindParam(':registration_date', $time);
|
|
|
|
$stmt->execute();
|
|
|
|
$_SESSION['username'] = $_POST['username'];
|
|
|
|
header('Location: ' . CONF['common']['prefix'] . '/');
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<form method="post">
|
|
|
|
<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>
|
|
|
|
<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>
|
|
|
|
<input type="submit">
|
|
</form>
|
|
|
|
Déjà un compte ? <a class="auth button" href="login">Se connecter</a>
|
|
|
|
<?php closeHTML(); ?>
|