Commit fc12b73e authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Feat : remove bankers and clients on remove user

Refactor : remove passwordHash field
parent e9a50fb4
Pipeline #5135 passed with stages
in 3 minutes and 23 seconds
......@@ -87,6 +87,23 @@ class HandleBanker {
Users.toggleModal("banker-modal", "banker-modal-card");
}
async deleteBanker(banker) {
try {
const response = await fetch("/api/UserBankers/" + banker.ID, {
method: "delete",
headers: new Headers({
"XSRF-Token": current_user.xsrftoken,
}),
});
if (response.status !== 200) {
throw new Error(`Banker could not be deleted (status ${response.status})`);
}
} catch (e) {
Messages.Show("is-warning", e.message);
console.error(e);
}
}
async postBanker() {
let method;
if (update_banker) method = "PUT";
......
......@@ -32,7 +32,7 @@ class HandleClient {
<div class="modal-background"></div>
<div class="modal-card" id="client-modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Ajout/Supression d'un client</p>
<p class="modal-card-title">Ajout/Édition d'un client</p>
<button class="delete" aria-label="close" id="client-modal-close"></button>
</header>
<section class="modal-card-body">
......@@ -101,6 +101,23 @@ class HandleClient {
Users.toggleModal("client-modal", "client-modal-card");
}
async deleteClient(client) {
try {
const response = await fetch("/api/UserClients/" + client.ID, {
method: "delete",
headers: new Headers({
"XSRF-Token": current_user.xsrftoken,
}),
});
if (response.status !== 200) {
throw new Error(`Client could not be deleted (status ${response.status})`);
}
} catch (e) {
Messages.Show("is-warning", e.message);
console.error(e);
}
}
async refreshBankers() {
const response = await fetch("/api/UserBankers/", {
method: "GET",
......
......@@ -10,7 +10,6 @@ let idOAuth_field;
let login_field;
let displayName_field;
let password_field;
let passwordhash_field;
let name_field;
let surname_field;
let role_field;
......@@ -64,11 +63,6 @@ class HandleUser {
<input class="input" type="text" id="users-modal-password" />
</div>
</div>
<div class="field" id="users-modal-password-container">
<div class="control">
<input class="input" type="hidden" id="users-modal-passwordhash" />
</div>
</div>
<div class="field" id="users-modal-name-container">
<label>Nom</label>
<div class="control">
......@@ -112,7 +106,6 @@ class HandleUser {
idOAuth_field = document.getElementById("users-modal-idoauth");
login_field = document.getElementById("users-modal-login");
password_field = document.getElementById("users-modal-password");
passwordhash_field = document.getElementById("users-modal-passwordhash");
displayName_field = document.getElementById("users-modal-displayName");
name_field = document.getElementById("users-modal-name");
surname_field = document.getElementById("users-modal-surname");
......@@ -138,7 +131,6 @@ class HandleUser {
id_field.value = "";
login_field.value = "";
password_field.value = RandomString(48);
passwordhash_field.value = "";
name_field.value = "";
displayName_field.value = "";
surname_field.value = "";
......@@ -162,6 +154,13 @@ class HandleUser {
Messages.Show("is-warning", e.message);
console.error(e);
}
if (user.role == "BANKER") {
let banker = await this.getBankerByUserID(user.id);
if (banker != undefined) this.parent.HandleBanker.deleteBanker(banker);
} else if (user.role == "CLIENT") {
let client = await Auth.getClientByUserID(user.id, current_user);
if (client != undefined) this.parent.HandleClient.deleteClient(client);
}
}
editUser(user) {
......@@ -171,7 +170,6 @@ class HandleUser {
idOAuth_field.value = user.idOAuth;
login_field.value = user.login;
password_field.value = "";
passwordhash_field.value = user.passwordHash;
name_field.value = user.name;
displayName_field.value = user.displayName;
surname_field.value = user.surname;
......@@ -223,7 +221,7 @@ class HandleUser {
else method = "POST";
try {
if(role_field.value == ""){
if (role_field.value == "") {
Messages.Show("is-warning", "Veuillez choisir un rôle pour l'utilisateur");
return;
}
......@@ -236,7 +234,6 @@ class HandleUser {
id: id_field.value,
login: login_field.value,
password: password_field.value,
passwordHash: passwordhash_field.value,
name: name_field.value,
surname: surname_field.value,
role: role_field.value,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment