Browse Source

working on user data update

feature/document
Stephan Richter 4 months ago
parent
commit
2dc45456f9
  1. 1
      frontend/src/Components/Login.svelte
  2. 4
      frontend/src/routes/user/EditableField.svelte
  3. 11
      frontend/src/routes/user/User.svelte
  4. 12
      frontend/src/user.svelte.js
  5. 1
      user/src/main/java/de/srsoftware/umbrella/user/Paths.java
  6. 30
      user/src/main/java/de/srsoftware/umbrella/user/UserModule.java

1
frontend/src/Components/Login.svelte

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
await checkUser();
});
</script>
<style>
label { display: block; margin: 5px; }
fieldset {

4
frontend/src/routes/user/EditableField.svelte

@ -2,7 +2,7 @@ @@ -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 @@ @@ -13,7 +13,7 @@
function check_key(evt){
if (evt.key === 'Enter'){
input = false;
checkUser();
onUpdate({key:key,value:value});
}
}
</script>

11
frontend/src/routes/user/User.svelte

@ -3,6 +3,15 @@ @@ -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 @@ @@ -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>

12
frontend/src/user.svelte.js

@ -3,18 +3,18 @@ export const user = $state({ @@ -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(){ @@ -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){ @@ -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!");
}

1
user/src/main/java/de/srsoftware/umbrella/user/Paths.java

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.user;
public class Paths {

30
user/src/main/java/de/srsoftware/umbrella/user/UserModule.java

@ -3,7 +3,6 @@ package de.srsoftware.umbrella.user; @@ -3,7 +3,6 @@ package de.srsoftware.umbrella.user;
import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.Constants.PASSWORD;
import static de.srsoftware.umbrella.core.Constants.REDIRECT;
import static de.srsoftware.umbrella.core.Paths.LOGOUT;
import static de.srsoftware.umbrella.core.ResponseCode.*;
import static de.srsoftware.umbrella.user.Constants.*;
@ -21,12 +20,10 @@ import de.srsoftware.umbrella.user.model.Password; @@ -21,12 +20,10 @@ import de.srsoftware.umbrella.user.model.Password;
import de.srsoftware.umbrella.user.model.Session;
import de.srsoftware.umbrella.user.model.Token;
import de.srsoftware.umbrella.user.model.UmbrellaUser;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
public class UserModule extends PathHandler {
@ -56,15 +53,11 @@ public class UserModule extends PathHandler { @@ -56,15 +53,11 @@ public class UserModule extends PathHandler {
headers.add("Access-Control-Allow-Origin", url);
headers.add("Access-Control-Allow-Headers", "Content-Type");
headers.add("Access-Control-Allow-Credentials", "true");
headers.add("Access-Control-Allow-Methods","GET, POST, PATCH");
}
return ex;
}
@Override
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
return sendEmptyResponse(200,addCors(ex));
}
@Override
public boolean doGet(Path path, HttpExchange ex) throws IOException {
var p = path.toString();
@ -75,6 +68,27 @@ public class UserModule extends PathHandler { @@ -75,6 +68,27 @@ public class UserModule extends PathHandler {
return super.doGet(path,ex);
}
@Override
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
return sendEmptyResponse(200,addCors(ex));
}
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
addCors(ex);
var head = path.pop();
try {
if (head == null || head.isBlank()) return sendContent(ex,UNPROCESSABLE,"User id missing!");
long userId = Long.parseLong(head);
var user = users.load(userId);
// TODO: update user, then return user data
} catch (NumberFormatException e) {
return sendContent(ex,UNPROCESSABLE,"Invalid user id: "+head);
} catch (UmbrellaException e) {
return sendContent(ex,e.statusCode(),e.getMessage());
}
return super.doPatch(path,ex);
}
@Override
public boolean doPost(Path path, HttpExchange ex) throws IOException {
addCors(ex);

Loading…
Cancel
Save