fix namespaces

add AccessDenied Page
This commit is contained in:
beo3000 2025-12-25 18:15:21 +01:00
parent 1484550939
commit 32c48d2bc3
7 changed files with 15 additions and 97 deletions

View File

@ -1,5 +1,6 @@
using Koogle.Application.Interfaces;
using Koogle.Application.Services;
using Koogle.Domain.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using System;
@ -29,6 +30,7 @@ namespace Koogle.Application
services.AddScoped<IDayService, DayService>();
services.AddScoped<IPersonExpenseService, PersonExpenseService>();
services.AddScoped<IDashboardService, DashboardService>();
services.AddScoped<IEmailService, StubEmailService>();
return services;
}

View File

@ -1,8 +1,4 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Koogle.Domain.Interfaces
namespace Koogle.Application.Interfaces
{
/// <summary>
/// Service interface for email notifications.

View File

@ -1,10 +1,8 @@
using Koogle.Application.Interfaces;
using Koogle.Domain.Interfaces;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Koogle.Infrastructure.Services;
namespace Koogle.Application.Services;
/// <summary>
/// Stub email service that logs instead of sending emails.

View File

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Koogle.Domain.Interfaces
{
public interface ICurrentUserService
{
/// <summary>
/// Die ID des aktuell angemeldeten Benutzers.
/// Gibt Guid.Empty zurück, wenn kein Benutzer angemeldet ist.
/// </summary>
int UserId { get; }
/// <summary>
/// Gibt an, ob ein Benutzer authentifiziert ist.
/// </summary>
bool IsAuthenticated { get; }
}
}

View File

@ -1,10 +1,8 @@
using Koogle.Domain.Interfaces;
using Koogle.Infrastrcuture.Services;
using Koogle.Infrastructure.Data;
using Koogle.Infrastructure.Identity;
using Koogle.Infrastructure.Repositories;
using Koogle.Infrastructure.Security;
using Koogle.Infrastructure.Services;
using KoogleApp.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
@ -75,9 +73,6 @@ public static class DependencyInjection
// HTTP Context Accessor (für CurrentUserService)
services.AddHttpContextAccessor();
// Current UserProfile Service
services.AddScoped<ICurrentUserService, CurrentUserService>();
// Repositories
services.AddScoped<IClubRepository, ClubRepository>();
services.AddScoped<IPersonRepository, PersonRepository>();
@ -86,7 +81,7 @@ public static class DependencyInjection
services.AddScoped<IPersonExpenseRepository, PersonExpenseRepository>();
// Services
services.AddScoped<IEmailService, StubEmailService>();
//services.AddScoped<IEmailService, StubEmailService>();
services.AddCascadingAuthenticationState();

View File

@ -1,60 +0,0 @@
using Koogle.Domain.Interfaces;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Koogle.Infrastrcuture.Services;
public class CurrentUserService : ICurrentUserService
{
private readonly IHttpContextAccessor _httpContextAccessor;
/// <summary>
/// Erstellt eine neue Instanz des CurrentUserService.
/// </summary>
/// <param name="httpContextAccessor">Der HTTP-Kontext-Accessor.</param>
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
/// <inheritdoc />
public int UserId
{
get
{
//var userIdClaim = _httpContextAccessor.HttpContext?.UserProfile?.FindFirst(ClaimTypes.NameIdentifier)?.Value
// ?? _httpContextAccessor.HttpContext?.UserProfile?.FindFirst("sub")?.Value
// ?? _httpContextAccessor.HttpContext?.UserProfile?.FindFirst("oid")?.Value;
var userIdClaim = _httpContextAccessor.HttpContext?.User?.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier")?.Value;
return 0;
//if (string.IsNullOrEmpty(userIdClaim))
// return Guid.Empty;
//// Versuche zuerst als Guid zu parsen (für interne UserProfile-IDs)
//if (Guid.TryParse(userIdClaim, out var userId))
// return userId;
//// Falls es eine Azure AD Object ID ist, generiere eine deterministische Guid daraus
//return GenerateDeterministicGuid(userIdClaim);
}
}
/// <inheritdoc />
public bool IsAuthenticated =>
_httpContextAccessor.HttpContext?.User?.Identity?.IsAuthenticated ?? false;
/// <summary>
/// Generiert eine deterministische Guid aus einem String.
/// </summary>
private static Guid GenerateDeterministicGuid(string input)
{
using var md5 = System.Security.Cryptography.MD5.Create();
var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input));
return new Guid(hash);
}
}

View File

@ -0,0 +1,9 @@
@page "/account/accessdenied"
<h3>AccessDenied</h3>
<LogoutButton/>
@code {
}