feat/Update_Controllers_to_Allow_for_Premium_Membership

This commit is contained in:
cesnimda
2026-08-03 09:17:28 +02:00
parent de937d25dc
commit c3f4a57195
187 changed files with 26062 additions and 991 deletions
+18 -1
View File
@@ -10,11 +10,28 @@ public interface ICurrentUserService
public sealed class CurrentUserService : ICurrentUserService
{
private readonly IHttpContextAccessor _http;
private string? _backgroundUserId;
public CurrentUserService(IHttpContextAccessor http)
{
_http = http;
}
public string? UserId => LocalAuthIdentity.GetRequiredUserId(_http.HttpContext?.User);
public string? UserId => _backgroundUserId ?? LocalAuthIdentity.GetRequiredUserId(_http.HttpContext?.User);
public IDisposable UseBackgroundUser(string userId)
{
if (string.IsNullOrWhiteSpace(userId)) throw new ArgumentException("A background owner is required.", nameof(userId));
if (_http.HttpContext is not null) throw new InvalidOperationException("Background owner scope cannot replace an HTTP request identity.");
var previous = _backgroundUserId;
_backgroundUserId = userId;
return new Reset(() => _backgroundUserId = previous);
}
private sealed class Reset(Action reset) : IDisposable
{
private Action? _reset = reset;
public void Dispose() => Interlocked.Exchange(ref _reset, null)?.Invoke();
}
}