Datensicherheit: Backup, Verschlüsselung, App-Sperre (Kapitel 13.3)
Automatisches rollierendes Backup der Datenbank beim Start mit Wiederherstellung über die Einstellungen, versionierte Schema-Migration, optionale Passwort-Verschlüsselung der LiteDB-Datei und eine App-Sperre nach Inaktivität mit eigenem Passwort. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -266,6 +266,118 @@
|
||||
</ScrollViewer>
|
||||
</ContentPage>
|
||||
|
||||
<!-- Tab: Sicherheit (13.3) -->
|
||||
<ContentPage Header="Sicherheit">
|
||||
<ScrollViewer>
|
||||
<StackPanel Margin="32,20,32,28" Spacing="24" MaxWidth="560">
|
||||
|
||||
<!-- Datensicherung -->
|
||||
<StackPanel Spacing="10">
|
||||
<TextBlock Text="Datensicherung" FontSize="16" FontWeight="SemiBold"/>
|
||||
<TextBlock Text="Bei jedem Start wird automatisch ein Backup der Datenbank angelegt (die letzten 10 werden behalten)."
|
||||
FontSize="12" Opacity="0.6" TextWrapping="Wrap"/>
|
||||
|
||||
<Button Content="Jetzt sichern" Command="{Binding CreateBackupNowCommand}"
|
||||
HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="{Binding BackupStatus}" Foreground="Green" FontSize="12"
|
||||
IsVisible="{Binding BackupStatus, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding Backups}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="vm:BackupListItem">
|
||||
<Border BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="0,0,0,1" Padding="0,7">
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<TextBlock Grid.Column="0" Text="{Binding Display}"
|
||||
VerticalAlignment="Center" FontSize="13"/>
|
||||
<Button Grid.Column="1" Content="Wiederherstellen" FontSize="12" Padding="10,4"
|
||||
Command="{Binding $parent[ItemsControl].((vm:SettingsViewModel)DataContext).RestoreBackupCommand}"
|
||||
CommandParameter="{Binding}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<TextBlock Text="Noch keine Backups vorhanden." Opacity="0.35" FontSize="12"
|
||||
IsVisible="{Binding !Backups.Count}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Separator/>
|
||||
|
||||
<!-- Datenbank-Verschlüsselung -->
|
||||
<StackPanel Spacing="10">
|
||||
<TextBlock Text="Datenbank-Verschlüsselung" FontSize="16" FontWeight="SemiBold"/>
|
||||
<TextBlock Text="Schützt die Datenbankdatei auf der Festplatte mit einem Passwort. Ohne das Passwort kann die App die Datenbank beim Start nicht öffnen — bei Verlust sind die Daten nicht mehr zugänglich."
|
||||
FontSize="12" Opacity="0.6" TextWrapping="Wrap"/>
|
||||
<TextBlock FontSize="13" FontWeight="SemiBold">
|
||||
<Run Text="Status: "/>
|
||||
<Run Text="{Binding DbEncryptionStatusLabel}"/>
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Spacing="4" IsVisible="{Binding IsDbEncrypted}">
|
||||
<TextBlock Text="Aktuelles Passwort" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding CurrentDbPassword}" PasswordChar="●"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid ColumnDefinitions="*,12,*">
|
||||
<StackPanel Grid.Column="0" Spacing="4">
|
||||
<TextBlock Text="Neues Passwort" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding NewDbPassword}" PasswordChar="●"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Spacing="4">
|
||||
<TextBlock Text="Wiederholen" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding NewDbPasswordConfirm}" PasswordChar="●"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding DbPasswordError}" Foreground="Red" FontSize="12"
|
||||
IsVisible="{Binding DbPasswordError, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Button Content="Passwort speichern" Command="{Binding SaveDbPasswordCommand}"/>
|
||||
<Button Content="Verschlüsselung entfernen" Command="{Binding RemoveDbPasswordCommand}"
|
||||
IsVisible="{Binding IsDbEncrypted}"/>
|
||||
</StackPanel>
|
||||
<TextBlock Text="Nach dem Ändern wird die App automatisch neu gestartet."
|
||||
FontSize="11" Opacity="0.5"/>
|
||||
</StackPanel>
|
||||
|
||||
<Separator/>
|
||||
|
||||
<!-- App-Sperre nach Inaktivität -->
|
||||
<StackPanel Spacing="10">
|
||||
<TextBlock Text="App-Sperre nach Inaktivität" FontSize="16" FontWeight="SemiBold"/>
|
||||
<TextBlock Text="Sperrt die Oberfläche nach einer Zeit ohne Maus-/Tastatureingabe. Eigenes Passwort, unabhängig von der Datenbank-Verschlüsselung."
|
||||
FontSize="12" Opacity="0.6" TextWrapping="Wrap"/>
|
||||
|
||||
<CheckBox Content="App-Sperre aktivieren" IsChecked="{Binding AppLockEnabled}"/>
|
||||
|
||||
<StackPanel Spacing="4" MaxWidth="200">
|
||||
<TextBlock Text="Zeit bis zur Sperre (Minuten)" FontSize="12" Opacity="0.7"/>
|
||||
<NumericUpDown Value="{Binding AppLockTimeoutMinutes}" Minimum="1" Maximum="120" FormatString="0"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid ColumnDefinitions="*,12,*">
|
||||
<StackPanel Grid.Column="0" Spacing="4">
|
||||
<TextBlock Text="Passwort (leer lassen, um es zu behalten)" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding AppLockNewPassword}" PasswordChar="●"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Spacing="4">
|
||||
<TextBlock Text="Wiederholen" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding AppLockNewPasswordConfirm}" PasswordChar="●"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding AppLockPasswordError}" Foreground="Red" FontSize="12"
|
||||
IsVisible="{Binding AppLockPasswordError, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||
|
||||
<Button Content="Speichern" Command="{Binding SaveAppLockSettingsCommand}" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="{Binding AppLockStatus}" Foreground="Green" FontSize="12"
|
||||
IsVisible="{Binding AppLockStatus, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</ContentPage>
|
||||
|
||||
</TabbedPage>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using LehrerApp.Desktop.ViewModels;
|
||||
using LehrerApp.Desktop.ViewModels.Settings;
|
||||
using LehrerApp.Desktop.Views.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace LehrerApp.Desktop.Views.Settings;
|
||||
|
||||
@@ -9,6 +12,30 @@ public partial class SettingsView : UserControl
|
||||
{
|
||||
public SettingsView() => InitializeComponent();
|
||||
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
if (DataContext is SettingsViewModel vm)
|
||||
{
|
||||
vm.OnConfirmRestore = ShowRestoreConfirmDialog;
|
||||
vm.OnAppLockChanged = () => App.Services.GetRequiredService<AppLockViewModel>().ApplyConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> ShowRestoreConfirmDialog(BackupListItem item)
|
||||
{
|
||||
var info = new ConfirmDialogInfo
|
||||
{
|
||||
Title = "Backup wiederherstellen?",
|
||||
Message = $"Die aktuelle Datenbank wird durch das Backup vom {item.Display} ersetzt. " +
|
||||
"Die App wird danach automatisch neu gestartet.",
|
||||
ConfirmText = "Wiederherstellen",
|
||||
};
|
||||
var dialog = new ConfirmDialog { DataContext = info };
|
||||
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||
return owner is not null && await dialog.ShowDialog<bool>(owner);
|
||||
}
|
||||
|
||||
private async void OnImportClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
|
||||
Reference in New Issue
Block a user