added auth with a simple UI

This commit is contained in:
2026-03-09 23:29:04 +01:00
parent c8347ac96b
commit 82ac241129
123 changed files with 3419 additions and 93 deletions

View File

@@ -0,0 +1,32 @@
using System.Text.Json;
using OED.Api.Core.Interfaces.Services;
using OED.Api.Core.Models.Eve;
using StackExchange.Redis;
namespace OED.Api.Infrastructure.Auth;
public class SessionService(IConnectionMultiplexer redis) : ISessionService
{
private readonly IDatabase _db = redis.GetDatabase();
private static readonly TimeSpan SessionTtl = TimeSpan.FromDays(7);
public async Task<string> CreateAsync(EveSession session)
{
var sessionId = Guid.NewGuid().ToString("N");
var json = JsonSerializer.Serialize(session);
await _db.StringSetAsync($"session:{sessionId}", json, SessionTtl);
return sessionId;
}
public async Task<EveSession?> GetAsync(string sessionId)
{
var json = await _db.StringGetAsync($"session:{sessionId}");
if (json.IsNullOrEmpty) return null;
return JsonSerializer.Deserialize<EveSession>((string)json!);
}
public async Task DeleteAsync(string sessionId)
{
await _db.KeyDeleteAsync($"session:{sessionId}");
}
}