Auth integration

This commit is contained in:
Wieland, Marc
2026-05-22 10:28:02 +02:00
parent 64c5f6aa2c
commit 7ab824e7c1
39 changed files with 681 additions and 57 deletions
+11 -4
View File
@@ -1,8 +1,10 @@
@page "/settings"
@rendermode InteractiveServer
@attribute [Authorize]
@inject TimetrackerService TrackerService
@inject HolidayService HolidayService
@inject ISnackbar Snackbar
@inject AuthenticationStateProvider AuthStateProvider
<PageTitle>Einstellungen Timetracker</PageTitle>
@@ -375,6 +377,7 @@ else
private static readonly System.Globalization.CultureInfo _deCulture = new("de-DE");
private AppSettings? _settings;
private int _userId;
private int _vacYear = DateTime.Today.Year;
private List<VacationDay> _vacationDays = [];
private DateTime? _newVacDateFrom;
@@ -402,14 +405,18 @@ else
protected override async Task OnInitializedAsync()
{
_settings = await TrackerService.GetSettingsAsync();
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
var claim = authState.User.FindFirst(ClaimTypes.NameIdentifier);
if (claim == null) return;
_userId = int.Parse(claim.Value);
_settings = await TrackerService.GetSettingsAsync(_userId);
await LoadVacations();
_holHolidays = await HolidayService.GetHolidaysAsync(_holYear);
}
private async Task LoadVacations()
{
_vacationDays = await TrackerService.GetVacationDaysAsync(_vacYear);
_vacationDays = await TrackerService.GetVacationDaysAsync(_userId, _vacYear);
}
private async Task ChangeYear(int delta)
@@ -438,7 +445,7 @@ else
{
if (_settings!.IsWorkDay(current.DayOfWeek))
{
await TrackerService.AddVacationDayAsync(new VacationDay { Date = current, Note = note });
await TrackerService.AddVacationDayAsync(new VacationDay { UserId = _userId, Date = current, Note = note });
added++;
}
current = current.AddDays(1);
@@ -452,7 +459,7 @@ else
private async Task RemoveVacation(int id)
{
await TrackerService.RemoveVacationDayAsync(id);
await TrackerService.RemoveVacationDayAsync(_userId, id);
await LoadVacations();
Snackbar.Add("Urlaubstag entfernt", Severity.Info);
}