149 lines
3.7 KiB
HTML
149 lines
3.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Utilisateurs</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
background-color: black;
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
/* Add padding to containers */
|
|
.container {
|
|
padding: 16px;
|
|
background-color: white;
|
|
display: block;
|
|
position: relative;
|
|
padding-left: 35px;
|
|
margin-bottom: 12px;
|
|
cursor: pointer;
|
|
font-size: 22px;
|
|
-webkit-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
user-select: none;
|
|
}
|
|
|
|
/* Full-width input fields */
|
|
input[type=text], input[type=password] {
|
|
width: 100%;
|
|
padding: 15px;
|
|
margin: 5px 0 22px 0;
|
|
display: inline-block;
|
|
border: none;
|
|
background: #f1f1f1;
|
|
}
|
|
|
|
input[type=text]:focus, input[type=password]:focus {
|
|
background-color: #ddd;
|
|
outline: none;
|
|
}
|
|
|
|
/* Overwrite default styles of hr */
|
|
hr {
|
|
border: 1px solid #f1f1f1;
|
|
margin-bottom: 25px;
|
|
}
|
|
|
|
/* Set a style for the submit button */
|
|
.registerbtn {
|
|
background-color: #04AA6D;
|
|
color: white;
|
|
padding: 16px 20px;
|
|
margin: 8px 0;
|
|
border: none;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.registerbtn:hover {
|
|
opacity: 1;
|
|
}
|
|
|
|
/* Add a blue text color to links */
|
|
a {
|
|
color: dodgerblue;
|
|
}
|
|
|
|
/* Set a grey background color and center the text of the "sign in" section */
|
|
.signin {
|
|
background-color: #f1f1f1;
|
|
text-align: center;
|
|
}
|
|
</style>
|
|
<script>
|
|
function createUserFromForm() {
|
|
const form = document.getElementById("userCreateForm");
|
|
let perms = 1;
|
|
for(const node of form.querySelectorAll('input[name="permissions"]')) {
|
|
perms += node.checked ? Number(node.value) : 0;
|
|
}
|
|
console.log(perms)
|
|
fetch(`/api/users/${form.username.value}`, {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
username: form.username.value,
|
|
permissions: perms,
|
|
password: form.password.value,
|
|
}),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
.then(async (response) => {
|
|
const res = await response.json();
|
|
console.log(res);
|
|
if(!response.ok) return alert(res.message);
|
|
window.location = `/dashboard/users/${res.username}`;
|
|
});
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<NAVBAR>
|
|
<form action="javascript:createUserFromForm()" id="userCreateForm">
|
|
<div class="container">
|
|
<h1>Création de compte</h1>
|
|
<p>Formulaire de création de compte.</p>
|
|
<hr>
|
|
|
|
<label for="username"><b>Nom d'utilisateur</b></label>
|
|
<input type="text" placeholder="Entrez le nom d'utilisateur" name="username" id="username" required>
|
|
|
|
<label for="psw"><b>Mot de passe</b></label>
|
|
<input type="password" placeholder="Mot de passe" name="password" id="psw" required>
|
|
|
|
<label for="psw-repeat"><b>Mot de passe (confirmation)</b></label>
|
|
<input type="password" placeholder="Répétez le mot de passe" name="password-repeat" id="psw-repeat" required>
|
|
<h4>Permissions</h4>
|
|
<label class="container">Appels
|
|
<input type="checkbox" name="permissions" value="2">
|
|
<span class="checkmark"></span>
|
|
</label>
|
|
<label class="container">Gestion des utilisateurs
|
|
<input type="checkbox" name="permissions" value="4">
|
|
<span class="checkmark"></span>
|
|
</label>
|
|
<label class="container">Gestion des contacts
|
|
<input type="checkbox" name="permissions" value="16">
|
|
<span class="checkmark"></span>
|
|
</label>
|
|
<label class="container">Admin
|
|
<input type="checkbox" name="permissions" value="8">
|
|
<span class="checkmark"></span>
|
|
</label>
|
|
<hr>
|
|
|
|
<button type="submit" class="registerbtn">Register</button>
|
|
</div>
|
|
</form>
|
|
|
|
</body>
|
|
</html>
|