2022-08-12 21:40:29 +02:00
|
|
|
checkToken();
|
2022-08-12 22:17:39 +02:00
|
|
|
signOut();
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("addUser").addEventListener("click", function(){
|
|
|
|
var updateProfil = ["pseudo", "email", "firstName", "birth", "password"];
|
|
|
|
var updateOk = true;
|
|
|
|
for (var i=0; i<updateProfil.length; i++){
|
|
|
|
if(document.getElementById(updateProfil[i]+"UpdateInput").value.length == 0){
|
|
|
|
updateOk = false;
|
|
|
|
document.getElementById(updateProfil[i]+"Alert").classList.remove("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(updateOk){
|
|
|
|
var selector = { "roles": ""};
|
|
|
|
var listSelector = [ "roles"];
|
|
|
|
for (var i=0; i<listSelector.length; i++){
|
|
|
|
var options = document.querySelectorAll("#"+listSelector[i]+"Selector option");
|
|
|
|
for (var j=0; j<options.length; j++){
|
|
|
|
if(options[j].selected){
|
|
|
|
selector[listSelector[i]] = options[j].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dataPut = {
|
|
|
|
|
|
|
|
"id": "",
|
|
|
|
"pseudo": document.getElementById("pseudoUpdateInput").value,
|
|
|
|
"email": document.getElementById("emailUpdateInput").value,
|
|
|
|
"name": document.getElementById("nameUpdateInput").value,
|
|
|
|
"firstName": document.getElementById("firstNameUpdateInput").value,
|
|
|
|
"birth": document.getElementById("birthUpdateInput").value,
|
|
|
|
"status": 1,
|
|
|
|
"password": document.getElementById("passwordUpdateInput").value,
|
|
|
|
"roles": selector["roles"],
|
|
|
|
"created_at": "",
|
|
|
|
"updated_at": "",
|
|
|
|
"deleted_at": "",
|
|
|
|
"connected_at": ""
|
|
|
|
|
|
|
|
}
|
|
|
|
instance({
|
|
|
|
method : "put",
|
|
|
|
url:"users",
|
|
|
|
withCredentials: true,
|
|
|
|
data: dataPut
|
|
|
|
}).then(function(response){
|
|
|
|
switch(response.status){
|
|
|
|
case 200:
|
|
|
|
location.reload();
|
|
|
|
break;
|
|
|
|
case 204:
|
|
|
|
console.log("Aucun contenu");
|
|
|
|
break;
|
|
|
|
case 401:
|
|
|
|
console.log("non autorisé");
|
|
|
|
break;
|
|
|
|
case 403:
|
|
|
|
console.log("interdit");
|
|
|
|
break;
|
|
|
|
case 500:
|
|
|
|
console.log("erreur interne");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("error inconnue");
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}).catch(function(error){
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|