implemented storing of user's language as well as loading
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { Router, Route } from 'svelte-tiny-router';
|
||||
|
||||
import { loadTranslation } from './translations.svelte.js';
|
||||
@@ -39,10 +38,11 @@
|
||||
|
||||
let translations_ready = $state(false);
|
||||
|
||||
onMount(async () => {
|
||||
await loadTranslation('de','Login');
|
||||
async function load(){
|
||||
loadTheme(user.theme);
|
||||
await loadTranslation(user.language?user.language:'de');
|
||||
translations_ready = true;
|
||||
});
|
||||
}
|
||||
|
||||
function loadTheme(name){
|
||||
if (!name) return;
|
||||
@@ -56,7 +56,7 @@
|
||||
next();
|
||||
}
|
||||
|
||||
$effect(() => loadTheme(user.theme));
|
||||
$effect(load);
|
||||
</script>
|
||||
|
||||
{#if translations_ready }
|
||||
|
||||
@@ -98,12 +98,26 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
case 3:
|
||||
createUserTables();
|
||||
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() {
|
||||
PasswordHasher<String> hasher;
|
||||
@@ -448,13 +462,13 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
Long id = user.id();
|
||||
var email = user.email() == null ? null : user.email().toString();
|
||||
if (id<1){
|
||||
insertInto(TABLE_USERS,LOGIN, PASS, THEME, EMAIL)
|
||||
.values(user.name(), user.hashedPassword(), user.theme(), email)
|
||||
insertInto(TABLE_USERS,LOGIN, PASS, THEME, EMAIL, LANGUAGE)
|
||||
.values(user.name(), user.hashedPassword(), user.theme(), email, user.language())
|
||||
.execute(db)
|
||||
.close();
|
||||
} else {
|
||||
replaceInto(TABLE_USERS, ID, LOGIN, PASS, THEME, EMAIL, LAST_LOGOFF)
|
||||
.values(id, user.name(), user.hashedPassword(), user.theme(), email, user.lastLogoff())
|
||||
replaceInto(TABLE_USERS, ID, LOGIN, PASS, THEME, EMAIL, LAST_LOGOFF, LANGUAGE)
|
||||
.values(id, user.name(), user.hashedPassword(), user.theme(), email, user.lastLogoff(), user.language())
|
||||
.execute(db)
|
||||
.close();
|
||||
}
|
||||
@@ -513,7 +527,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.getString(EMAIL) instanceof String addr && !addr.isBlank() ? new EmailAddress(addr) : null,
|
||||
Password.of(rs.getString(PASS)),
|
||||
rs.getString(THEME),
|
||||
"de", // TODO: save in DB
|
||||
rs.getString(LANGUAGE),
|
||||
perms,
|
||||
rs.getLong(LAST_LOGOFF)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user