working on user data update
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
await checkUser();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
label { display: block; margin: 5px; }
|
||||
fieldset {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { checkUser } from '../../user.svelte.js';
|
||||
|
||||
let { key, value } = $props();
|
||||
let { key, onUpdate, value } = $props();
|
||||
|
||||
let input = $state(false);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
function check_key(evt){
|
||||
if (evt.key === 'Enter'){
|
||||
input = false;
|
||||
checkUser();
|
||||
onUpdate({key:key,value:value});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
import { user } from '../../user.svelte.js';
|
||||
import EditableField from './EditableField.svelte';
|
||||
|
||||
async function patch(changeset){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${user.id}`;
|
||||
|
||||
await fetch(url,{
|
||||
method: 'PATCH',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(changeset)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<h1>{t('user.user_module')}</h1>
|
||||
|
||||
@@ -16,7 +25,7 @@
|
||||
<th>{t('user.id')}</th>
|
||||
<td>{user.id}</td>
|
||||
</tr>
|
||||
<EditableField key='user.name' value={user.name} />
|
||||
<EditableField key='user.name' value={user.name} onUpdate={patch} />
|
||||
<EditableField key='user.login' value={user.login} />
|
||||
<EditableField key='user.email' value={user.email} />
|
||||
<tr>
|
||||
|
||||
@@ -3,18 +3,18 @@ export const user = $state({
|
||||
})
|
||||
|
||||
export async function checkUser(){
|
||||
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/whoami`;
|
||||
let response = await fetch(url,{
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/whoami`;
|
||||
const response = await fetch(url,{
|
||||
credentials: 'include'
|
||||
});
|
||||
if (response.ok){
|
||||
const json = await response.json();
|
||||
for (var key of Object.keys(json)) user[key] = json[key];
|
||||
for (let key of Object.keys(json)) user[key] = json[key];
|
||||
}
|
||||
}
|
||||
|
||||
export async function logout(){
|
||||
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/logout`;
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/logout`;
|
||||
await fetch(url,{
|
||||
credentials: 'include'
|
||||
});
|
||||
@@ -22,7 +22,7 @@ export async function logout(){
|
||||
}
|
||||
|
||||
export async function tryLogin(credentials){
|
||||
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/login`;
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/login`;
|
||||
let response = await fetch(url,{
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
@@ -33,7 +33,7 @@ export async function tryLogin(credentials){
|
||||
});
|
||||
if (response.ok){
|
||||
const json = await response.json();
|
||||
for (var key of Object.keys(json)) user[key] = json[key];
|
||||
for (let key of Object.keys(json)) user[key] = json[key];
|
||||
} else {
|
||||
alert("Login failed!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user