add a partial user to be returned
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
import Home from "./pages/home/home.svelte";
|
||||
import Router, {link} from 'svelte-spa-router';
|
||||
import Profil from "./pages/profil/profil.svelte";
|
||||
import UpdateProfil from "./pages/profil/updateProfil.svelte";
|
||||
|
||||
const routes = {
|
||||
"/": Home,
|
||||
"/login": Login,
|
||||
"/profil": Profil,
|
||||
"/update-profil": UpdateProfil,
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
import Router, { link } from "svelte-spa-router";
|
||||
import Login from "../auth/login.svelte";
|
||||
import Profil from "../profil/profil.svelte";
|
||||
import UpdateProfil from "../profil/updateProfil.svelte";
|
||||
const routes = {
|
||||
"/login": Login,
|
||||
"/profil": Profil,
|
||||
"/update-profil": UpdateProfil,
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -31,6 +33,16 @@
|
||||
Profil
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a
|
||||
href="/update-profil"
|
||||
use:link
|
||||
class="nav-link active"
|
||||
aria-current="page"
|
||||
>
|
||||
Update Profile
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<script>
|
||||
import { onMount } from "svelte";
|
||||
|
||||
|
||||
let username;
|
||||
let image_url;
|
||||
let gAuth = false;
|
||||
let errors = {username, image_url};
|
||||
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;
|
||||
gAuth = data.isEnabledTwoFactorAuth;
|
||||
});
|
||||
});
|
||||
|
||||
$: submit = async() => {
|
||||
errors.username = "";
|
||||
errors.image_url ="";
|
||||
if (username === undefined || username.trim() === "") {
|
||||
errors.username = "Username is required";
|
||||
return;
|
||||
}
|
||||
if (image_url === undefined || image_url.trim() === "") {
|
||||
errors.image_url = "image_url is required";
|
||||
return;
|
||||
}
|
||||
await fetch("http://transcendance:8080/api/v2/user/",
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({
|
||||
"username": username,
|
||||
"image_url": image_url,
|
||||
"isEnabledTwoFactorAuth": gAuth
|
||||
})});
|
||||
};
|
||||
</script>
|
||||
|
||||
<body>
|
||||
<main class="form-signin w-100 m-auto">
|
||||
<div class="p-20">
|
||||
{#if errors.username}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{errors.username}
|
||||
</div>
|
||||
{/if}
|
||||
{#if errors.image_url}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{errors.image_url}
|
||||
</div>
|
||||
{/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} />
|
||||
|
||||
<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" />
|
||||
|
||||
<div>
|
||||
<input type="checkbox" bind:checked={gAuth} id="gAuth" name="gAuth">
|
||||
<label for="gAuth">Enable google authenticator</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="p-2 bg-blue-500 text-white mt-4 px-6">
|
||||
Change
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
<style>
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.form-signin {
|
||||
max-width: 330px;
|
||||
padding: 15px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user