implemented storing of user's language as well as loading

This commit is contained in:
2025-09-22 17:42:20 +02:00
parent 60c9a956aa
commit f916a2c5ae
2 changed files with 26 additions and 12 deletions

View File

@@ -1,5 +1,4 @@
<script> <script>
import { onMount } from 'svelte';
import { Router, Route } from 'svelte-tiny-router'; import { Router, Route } from 'svelte-tiny-router';
import { loadTranslation } from './translations.svelte.js'; import { loadTranslation } from './translations.svelte.js';
@@ -39,10 +38,11 @@
let translations_ready = $state(false); let translations_ready = $state(false);
onMount(async () => { async function load(){
await loadTranslation('de','Login'); loadTheme(user.theme);
await loadTranslation(user.language?user.language:'de');
translations_ready = true; translations_ready = true;
}); }
function loadTheme(name){ function loadTheme(name){
if (!name) return; if (!name) return;
@@ -56,7 +56,7 @@
next(); next();
} }
$effect(() => loadTheme(user.theme)); $effect(load);
</script> </script>
{#if translations_ready } {#if translations_ready }

View File

@@ -98,12 +98,26 @@ CREATE TABLE IF NOT EXISTS {0} (
case 3: case 3:
createUserTables(); createUserTables();
createLoginServiceTables(); createLoginServiceTables();
case 4:
createLanguageColumn();
} }
return setCurrentVersion(4); return setCurrentVersion(5);
} }
private void createLanguageColumn() {
var sql = "ALTER TABLE {0} ADD COLUMN {1} VARCHAR(10)";
try {
var stmt = db.prepareStatement(format(sql,TABLE_USERS,LANGUAGE));
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed to create column {1} in {0}",TABLE_USERS, LANGUAGE,e);
throw new RuntimeException(e);
}
}
private void createUserTables() { private void createUserTables() {
PasswordHasher<String> hasher; PasswordHasher<String> hasher;
@@ -448,13 +462,13 @@ CREATE TABLE IF NOT EXISTS {0} (
Long id = user.id(); Long id = user.id();
var email = user.email() == null ? null : user.email().toString(); var email = user.email() == null ? null : user.email().toString();
if (id<1){ if (id<1){
insertInto(TABLE_USERS,LOGIN, PASS, THEME, EMAIL) insertInto(TABLE_USERS,LOGIN, PASS, THEME, EMAIL, LANGUAGE)
.values(user.name(), user.hashedPassword(), user.theme(), email) .values(user.name(), user.hashedPassword(), user.theme(), email, user.language())
.execute(db) .execute(db)
.close(); .close();
} else { } else {
replaceInto(TABLE_USERS, ID, LOGIN, PASS, THEME, EMAIL, LAST_LOGOFF) replaceInto(TABLE_USERS, ID, LOGIN, PASS, THEME, EMAIL, LAST_LOGOFF, LANGUAGE)
.values(id, user.name(), user.hashedPassword(), user.theme(), email, user.lastLogoff()) .values(id, user.name(), user.hashedPassword(), user.theme(), email, user.lastLogoff(), user.language())
.execute(db) .execute(db)
.close(); .close();
} }
@@ -513,7 +527,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.getString(EMAIL) instanceof String addr && !addr.isBlank() ? new EmailAddress(addr) : null, rs.getString(EMAIL) instanceof String addr && !addr.isBlank() ? new EmailAddress(addr) : null,
Password.of(rs.getString(PASS)), Password.of(rs.getString(PASS)),
rs.getString(THEME), rs.getString(THEME),
"de", // TODO: save in DB rs.getString(LANGUAGE),
perms, perms,
rs.getLong(LAST_LOGOFF) rs.getLong(LAST_LOGOFF)
); );