forked from v4l3n71n/covas-bo
Merge pull request 'integ-fastapi' (#1) from integ-fastapi into master
Reviewed-on: #1
This commit is contained in:
commit
bea9614fac
@ -119,16 +119,16 @@
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
|
||||
<div class="alert alert-warning alert-dismissible hidden" id="notModifiedAlert" role="alert">
|
||||
<div>Utilisateur non modifié</div>
|
||||
<div>Utilisateur non ajouté, car le pseudo ou l'adresse mail existe déjà</div>
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success alert-dismissible hidden" id="createUserAlert" role="alert">
|
||||
<div>Vous avez créer l'utilisateur <span id="displayUser"></span></div>
|
||||
<div>Vous avez créée l'utilisateur <span id="displayUser"></span></div>
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-warning alert-dismissible hidden" id="pseudoExistAlert" role="alert">
|
||||
<div class="alert alert-warning alert-dismissible hidden" id="usernameExistAlert" role="alert">
|
||||
<div>Pseudo déjà pris</div>
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
@ -153,6 +153,11 @@
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-danger alert-dismissible hidden" id="syntaxAlert" role="alert">
|
||||
<div>Erreur d'entrée dans le formulaire</div>
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-danger alert-dismissible hidden" id="unknownAlert" role="alert">
|
||||
<div>Erreur inconnue</div>
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
@ -164,8 +169,8 @@
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text" id="pseudoUpdate">Pseudo</span>
|
||||
<input id="pseudoUpdateInput" type="text" class="form-control" placeholder="Pseudo" aria-label="Pseudo" aria-describedby="pseudoUpdate">
|
||||
<span class="input-group-text" id="usernameUpdate">Pseudo</span>
|
||||
<input id="usernameUpdateInput" type="text" class="form-control" placeholder="Pseudo" aria-label="Pseudo" aria-describedby="usernameUpdate">
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
|
@ -150,7 +150,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="alert alert-danger alert-dismissible hidden" id="pseudoAlert" role="alert">
|
||||
<div class="alert alert-danger alert-dismissible hidden" id="usernameAlert" role="alert">
|
||||
<div>Champ pseudo vide</div>
|
||||
<button type="button" class="btn-close" aria-label="Close"></button>
|
||||
</div>
|
||||
@ -180,8 +180,8 @@
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text" id="pseudoUpdate">Pseudo</span>
|
||||
<input id="pseudoUpdateInput" type="text" class="form-control" placeholder="Pseudo" aria-label="Pseudo" aria-describedby="pseudoUpdate">
|
||||
<span class="input-group-text" id="usernameUpdate">Pseudo</span>
|
||||
<input id="usernameUpdateInput" type="text" class="form-control" placeholder="Pseudo" aria-label="Pseudo" aria-describedby="usernameUpdate">
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
|
@ -156,23 +156,33 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<button type="button" class="btn btn-success" id="enableUserButton" data-bs-toggle="modal" data-bs-target="#enableUserModal">Activer l'utilisateur</button>
|
||||
|
||||
<button type="button" class="btn btn-warning " id="disableUserButton" data-bs-toggle="modal" data-bs-target="#disableUserModal">Désactiver l'utilisateur</button>
|
||||
<button type="button" class="btn btn-danger" id="removeUserButton" data-bs-toggle="modal" data-bs-target="#removeUserModal">Supprimer l'utilisateur</button>
|
||||
<br /><br /><br />
|
||||
<table id=users class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" id="checkboxPrincipal" aria-label="Checkbox for following text input"></th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Pseudo</th>
|
||||
<th scope="col">Username</th>
|
||||
<th scope="col">Mail</th>
|
||||
<th scope="col">Rôle</th>
|
||||
<th scope="col">Statut</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><input type="checkbox" class="checkboxList" userid="" aria-label="Checkbox for following text input"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td><span class="activeStatus hidden">Activé</span><span class="disableStatus hidden">Désactivé</span><span class="confirmStatus hidden">En attente de confirmation</span><span class="removeStatus hidden">En attente de suppression</span><span class="unknownStatus hidden">Statut inconnu</span></td>
|
||||
<td><button type="button" class="btn btn-primary" data-bs-toggle="modal" userid="" data-bs-target="#updateUserModal">Modifier</button></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
|
@ -4,7 +4,7 @@ closeButton();
|
||||
|
||||
|
||||
document.getElementById("addUser").addEventListener("click", function(){
|
||||
var updateProfil = ["pseudo", "email", "firstName", "birth", "password"];
|
||||
var updateProfil = ["username", "email", "firstName", "birth", "password"];
|
||||
var updateOk = true;
|
||||
for (var i=0; i<updateProfil.length; i++){
|
||||
if(document.getElementById(updateProfil[i]+"UpdateInput").value.length == 0){
|
||||
@ -27,7 +27,7 @@ document.getElementById("addUser").addEventListener("click", function(){
|
||||
dataPut = {
|
||||
|
||||
"id": "",
|
||||
"pseudo": document.getElementById("pseudoUpdateInput").value,
|
||||
"username": document.getElementById("usernameUpdateInput").value,
|
||||
"email": document.getElementById("emailUpdateInput").value,
|
||||
"name": document.getElementById("nameUpdateInput").value,
|
||||
"firstName": document.getElementById("firstNameUpdateInput").value,
|
||||
@ -51,7 +51,7 @@ document.getElementById("addUser").addEventListener("click", function(){
|
||||
switch(response.status){
|
||||
case 201:
|
||||
idAlert="createUser"
|
||||
var user = document.getElementById("pseudoUpdateInput").value;
|
||||
var user = document.getElementById("usernameUpdateInput").value;
|
||||
if(user.length > 0){
|
||||
document.getElementById("displayUser").textContent=user;
|
||||
}
|
||||
@ -68,7 +68,7 @@ document.getElementById("addUser").addEventListener("click", function(){
|
||||
console.log(error);
|
||||
switch(error.response.status){
|
||||
case 401:
|
||||
listExist = [ "pseudo", "email" ];
|
||||
listExist = [ "username", "email" ];
|
||||
for(var i=0; i<listExist.length; i++){
|
||||
if(error.response.data[listExist[i]]){
|
||||
document.getElementById(listExist[i]+"ExistAlert").classList.remove("hidden");
|
||||
@ -79,6 +79,9 @@ document.getElementById("addUser").addEventListener("click", function(){
|
||||
case 403:
|
||||
idAlert="forbidden";
|
||||
break;
|
||||
case 403:
|
||||
idAlert="syntaxe";
|
||||
break;
|
||||
case 500:
|
||||
idAlert="internalServer";
|
||||
break;
|
||||
|
@ -1 +1 @@
|
||||
const instance = axios.create({ baseURL: 'http://localhost:8083/api'});
|
||||
const instance = axios.create({ baseURL: 'http://localhost:8083', withCredentials: true});
|
@ -54,13 +54,11 @@ function buildParam(e, id){
|
||||
if(search.length > 0){
|
||||
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(search)){
|
||||
param = param + "email="+search+"&";
|
||||
} else if(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(search)){
|
||||
param = param + "uuid="+search+"&";
|
||||
} else {
|
||||
param = param + "search="+search+"&";
|
||||
param = param + "id="+search+"&";
|
||||
}
|
||||
} else {
|
||||
listParam.push("email"); listParam.push("uuid"); listParam.push("search");
|
||||
listParam.push("email"); listParam.push("id");
|
||||
}
|
||||
|
||||
for (var i=0; i<listParam.length; i++){
|
||||
|
@ -6,8 +6,16 @@ document.getElementById("signin").addEventListener("submit", function(evt){
|
||||
var pseudo = document.getElementById("floatingPseudo");
|
||||
var password = document.getElementById("floatingPassword");
|
||||
if((password.value.length > 0) || (pseudo.value.length > 0)){
|
||||
instance.get("token", { auth : {username: pseudo.value, password: password.value}, withCredentials: true})
|
||||
.then(function(response) { location.href="html/users.html"; })
|
||||
authData = {username: pseudo.value, password: password.value}
|
||||
instance.post("token", {username: pseudo.value, password: password.value}, {headers: {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded' }})
|
||||
.then(function(response) {
|
||||
if(response.data["roles"] == "Admin"){
|
||||
location.href="html/users.html";
|
||||
}
|
||||
else {
|
||||
instance.delete("token")
|
||||
}
|
||||
})
|
||||
.catch(function(error){
|
||||
|
||||
switch (error.response.status){
|
||||
|
@ -6,7 +6,7 @@ var id = getQuery("id");
|
||||
if(id.length > 0){
|
||||
instance.get("users/"+id, {withCredentials: true})
|
||||
.then(function(response){
|
||||
var listValue = [ "id", "pseudo", "name", "firstName", "email", "birth"];
|
||||
var listValue = [ "id", "username", "name", "firstName", "email", "birth"];
|
||||
var listTime = ["connected_at", "created_at", "updated_at", "deleted_at"];
|
||||
for (var i=0; i<listValue.length; i++){
|
||||
if(response.data[listValue[i]] != null){
|
||||
@ -64,15 +64,15 @@ if(id.length > 0){
|
||||
switch(e.currentTarget.id){
|
||||
case "disableUserButton":
|
||||
httpMethod = "delete";
|
||||
httpUrl = "users/disable/"+idInput;
|
||||
httpUrl = "users/"+idInput;
|
||||
break;
|
||||
case "removeUserButton":
|
||||
httpMethod = "delete";
|
||||
httpUrl = "users/"+idInput;
|
||||
httpUrl = "users/"+idInput+"?remove=true";
|
||||
break;
|
||||
default:
|
||||
httpMethod = "patch";
|
||||
httpUrl = "users/enable/"+idInput;
|
||||
httpUrl = "users/"+idInput;
|
||||
break;
|
||||
}
|
||||
instance({
|
||||
@ -101,7 +101,7 @@ if(id.length > 0){
|
||||
|
||||
|
||||
document.getElementById("updateUserButton").addEventListener("click", function(){
|
||||
var updateProfil = ["id", "pseudo", "email", "firstName", "birth"];
|
||||
var updateProfil = ["id", "username", "email", "firstName", "birth"];
|
||||
var updateOk = true;
|
||||
for (var i=0; i<updateProfil.length; i++){
|
||||
if(document.getElementById(updateProfil[i]+"UpdateInput").value.length == 0){
|
||||
@ -122,9 +122,8 @@ if(id.length > 0){
|
||||
}
|
||||
|
||||
dataPut = {
|
||||
|
||||
"id": id,
|
||||
"pseudo": document.getElementById("pseudoUpdateInput").value,
|
||||
"id": document.getElementById("idUpdateInput").value,
|
||||
"username": document.getElementById("usernameUpdateInput").value,
|
||||
"email": document.getElementById("emailUpdateInput").value,
|
||||
"name": document.getElementById("nameUpdateInput").value,
|
||||
"firstName": document.getElementById("firstNameUpdateInput").value,
|
||||
@ -139,8 +138,8 @@ if(id.length > 0){
|
||||
|
||||
}
|
||||
instance({
|
||||
method : "patch",
|
||||
url:"users/"+id,
|
||||
method : "put",
|
||||
url:"users/"+document.getElementById("idUpdateInput").value,
|
||||
withCredentials: true,
|
||||
data: dataPut
|
||||
}).then(function(response){
|
||||
|
@ -2,7 +2,7 @@ checkToken();
|
||||
signOut();
|
||||
var param = {}
|
||||
|
||||
param["nbPages"] = 20;
|
||||
param["limit"] = 20;
|
||||
|
||||
var listSearch = [ "email", "uuid", "search"];
|
||||
for(var i=0; i<listSearch.length; i++){
|
||||
@ -30,8 +30,8 @@ for (var i=0; i<listQuery.length; i++){
|
||||
|
||||
instance.get("users/count", { withCredentials: true }).then(function(response){
|
||||
|
||||
var count = response.data / param["nbPages"];
|
||||
var reste = response.data % param["nbPages"];
|
||||
var count = response.data["count"] / param["limit"];
|
||||
var reste = response.data["count"] % param["limit"];
|
||||
var total = 0;
|
||||
if(reste != 0){
|
||||
total = Number.parseInt(count) + 1;
|
||||
@ -39,7 +39,7 @@ instance.get("users/count", { withCredentials: true }).then(function(response){
|
||||
|
||||
if(total > 1){
|
||||
document.getElementById("page").classList.remove("hidden");
|
||||
var pageCurrent = getQuery("page");
|
||||
var pageCurrent = getQuery("skip");
|
||||
var page = 1;
|
||||
if(pageCurrent.length > 0){
|
||||
page = Number.parseInt(pageCurrent);
|
||||
@ -68,14 +68,14 @@ instance.get("users/count", { withCredentials: true }).then(function(response){
|
||||
|
||||
});
|
||||
|
||||
param["page"] = 0;
|
||||
var pageCurrent = getQuery("page");
|
||||
param["skip"] = 0;
|
||||
var pageCurrent = getQuery("skip");
|
||||
if (pageCurrent.length > 0){
|
||||
param["page"] = Number.parseInt(pageCurrent);
|
||||
param["page"] = param["page"] - 1;
|
||||
param["skip"] = Number.parseInt(pageCurrent);
|
||||
param["skip"] = param["skip"] - 1;
|
||||
}
|
||||
|
||||
var listQuery = ["search", "uuid", "roles", "status", "email"];
|
||||
var listQuery = ["search", "id", "roles", "status", "email"];
|
||||
for (var i=0; i<listQuery.length; i++){
|
||||
var query = getQuery(listQuery[i]);
|
||||
if(query.length > 0){
|
||||
@ -89,6 +89,58 @@ instance.get("users", {withCredentials: true, params :param}).then(function(resp
|
||||
var listData = []
|
||||
listData.push(response.data);
|
||||
}
|
||||
if(listData.length > 0 ){
|
||||
var listModalButton = ["disable", "enable", "remove"];
|
||||
|
||||
for (var i=0; i<listModalButton.length; i++){
|
||||
document.getElementById(listModalButton[i]+"UserButton").addEventListener("click", function(e){
|
||||
var httpMethod = ""
|
||||
var httpUrl = "";
|
||||
param = {};
|
||||
userids= [];
|
||||
checkboxList = document.getElementsByClassName("checkboxList");
|
||||
for (var j=0; j<checkboxList.length; j++){
|
||||
if(checkboxList[j].checked){
|
||||
userid = checkboxList[j].getAttribute("userid");
|
||||
if (userid.length > 0){
|
||||
userids.push(userid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
param["ids"]=userids;
|
||||
|
||||
switch(e.currentTarget.id){
|
||||
case "disableUserButton":
|
||||
httpMethod = "delete";
|
||||
httpUrl = "users/groups";
|
||||
break;
|
||||
case "removeUserButton":
|
||||
httpMethod = "delete";
|
||||
httpUrl = "users/groups?remove=true";
|
||||
break;
|
||||
default:
|
||||
httpMethod = "patch";
|
||||
httpUrl = "users/groups";
|
||||
break;
|
||||
}
|
||||
instance({
|
||||
method: httpMethod,
|
||||
url: httpUrl,
|
||||
data:param,
|
||||
withCredentials: true
|
||||
})
|
||||
.then(function(response){
|
||||
if(response.status == 200){
|
||||
location.href="/html/users.html";
|
||||
}
|
||||
})
|
||||
.catch(function(error){
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
for (var i=0; i<listData.length; i++){
|
||||
var trTag = document.querySelector("#users tbody tr").cloneNode(true);
|
||||
if(i != 0){
|
||||
@ -96,10 +148,11 @@ instance.get("users", {withCredentials: true, params :param}).then(function(resp
|
||||
}
|
||||
var trAll = document.querySelectorAll("#users tbody tr")
|
||||
td = trAll[i].querySelectorAll("td");
|
||||
td[0].textContent = listData[i].id;
|
||||
td[1].textContent = listData[i].pseudo;
|
||||
td[2].textContent = listData[i].email;
|
||||
td[3].textContent = listData[i].roles;
|
||||
td[0].querySelector("input").setAttribute("userid", listData[i].id)
|
||||
td[1].textContent = listData[i].id;
|
||||
td[2].textContent = listData[i].username;
|
||||
td[3].textContent = listData[i].email;
|
||||
td[4].textContent = listData[i].roles;
|
||||
var classTd = "";
|
||||
switch(listData[i].status){
|
||||
case 1:
|
||||
@ -118,15 +171,25 @@ instance.get("users", {withCredentials: true, params :param}).then(function(resp
|
||||
classTd = ".unknownStatus"
|
||||
break;
|
||||
}
|
||||
td[4].querySelector(".activeStatus").classList.add("hidden");
|
||||
td[4].querySelector(classTd).classList.remove("hidden");
|
||||
td[5].querySelector(".activeStatus").classList.add("hidden");
|
||||
td[5].querySelector(classTd).classList.remove("hidden");
|
||||
|
||||
trAll[i].addEventListener("click", function(e){
|
||||
var id = e.currentTarget.querySelector("td").textContent;
|
||||
td[6].querySelector("button").setAttribute("userid", listData[i].id)
|
||||
|
||||
td[6].querySelector("button").addEventListener("click", function(e){
|
||||
var id = e.currentTarget.getAttribute("userid");
|
||||
location.href="/html/user.html?id="+id;
|
||||
});
|
||||
|
||||
}
|
||||
document.getElementById("checkboxPrincipal").addEventListener("click", function(e){
|
||||
listCheck = document.getElementsByClassName("checkboxList");
|
||||
var checkPrincipal = e.currentTarget.checked;
|
||||
for (var i=0; i<listCheck.length; i++){
|
||||
listCheck[i].checked = checkPrincipal;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user