Ajout de l'update utilisateur avec seulement certaines string + un exemple avec svelte
This commit is contained in:
@@ -2,41 +2,45 @@
|
||||
import { onMount } from "svelte";
|
||||
|
||||
|
||||
let username;
|
||||
let image_url;
|
||||
let usernameSv = "";
|
||||
let image_urlSv = "";
|
||||
let gAuth = false;
|
||||
let errors = {username, image_url};
|
||||
let errors = {usernameSv, image_urlSv};
|
||||
onMount(async () => {
|
||||
await fetch("http://transcendance:8080/api/v2/user").
|
||||
then(response => response.json()).
|
||||
then(data => {
|
||||
console.log(data);
|
||||
username = data.username;
|
||||
image_url = data.image_url;
|
||||
usernameSv = data.username;
|
||||
image_urlSv = data.image_url;
|
||||
gAuth = data.isEnabledTwoFactorAuth;
|
||||
});
|
||||
});
|
||||
|
||||
$: submit = async() => {
|
||||
errors.username = "";
|
||||
errors.image_url ="";
|
||||
if (username === undefined || username.trim() === "") {
|
||||
errors.username = "Username is required";
|
||||
errors.usernameSv = "";
|
||||
errors.image_urlSv ="";
|
||||
if (usernameSv === undefined || usernameSv.trim() === "") {
|
||||
errors.usernameSv = "Username is required";
|
||||
return;
|
||||
}
|
||||
if (image_url === undefined || image_url.trim() === "") {
|
||||
errors.image_url = "image_url is required";
|
||||
if (image_urlSv === undefined || image_urlSv.trim() === "") {
|
||||
errors.image_urlSv = "image_url is required";
|
||||
return;
|
||||
}
|
||||
console.log(usernameSv);
|
||||
await fetch("http://transcendance:8080/api/v2/user/",
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"username": username,
|
||||
"image_url": image_url,
|
||||
"isEnabledTwoFactorAuth": gAuth
|
||||
})});
|
||||
};
|
||||
"username" : usernameSv,
|
||||
"image_url" : image_urlSv,
|
||||
"isEnabledTwoFactorAuth" : gAuth
|
||||
})
|
||||
})
|
||||
};
|
||||
</script>
|
||||
|
||||
<body>
|
||||
@@ -54,10 +58,10 @@
|
||||
{/if}
|
||||
<form on:submit|preventDefault={submit}>
|
||||
<label for="username" class="block text-sm text-gray-600">Username</label>
|
||||
<input id="username" type="text" placeholder="username" class="block px-1 py-2 mt-2 border-2 border-gray-100 text-gray-800" bind:value={username} />
|
||||
<input id="username" type="text" placeholder=${usernameSv} class="block px-1 py-2 mt-2 border-2 border-gray-100 text-gray-800" bind:value={usernameSv} />
|
||||
|
||||
<label for="image_url" class="block text-sm text-gray-600 mt-4">image_url</label>
|
||||
<input id="image_url" type="image_url" bind:value={image_url} placeholder="image_url" class="block px-1 py-2 mt-2 border-2 border-gray-100 text-gray-800" />
|
||||
<input id="image_url" type="image_url" bind:value={image_urlSv} placeholder=${image_urlSv} class="block px-1 py-2 mt-2 border-2 border-gray-100 text-gray-800" />
|
||||
|
||||
<div>
|
||||
<input type="checkbox" bind:checked={gAuth} id="gAuth" name="gAuth">
|
||||
|
||||
Reference in New Issue
Block a user