Files
Govor/Govor.API/Common/Extensions/SessionAuthorization.cs
T
Artemy 29cc51ee0c Add reactions, reliable push & session checks
Implements message reactions and reaction packs (domain models, services, admin HTTP API, media processing via ImageSharp and limits) and adds reliable push delivery (ChatPushNotification, ChatPushDispatcher, ChatPushWorker, improved ChatNotificationService). Enhances message reading (ReadChat API, unread counts, concurrency-safe receipts) and tightens session security (access-token session validation in JWT, hub filter, SessionAuthorization). Improves SignalR behavior (session groups, reaction/channel events, hub/error mappings). Adds EF migrations, many controller fixes (Forbid handling, password API), tests (Govor.Server.Tests), docs, CI and tooling updates (Dockerfile → .NET 10, GH Actions matrix for sqlite/postgres, Govor.Server.slnx, global.json), and small infra changes (AutoMapper bump, NullPushProvider, storage/token handling).
2026-10-03 17:42:24 +07:00

22 lines
802 B
C#

#nullable enable
using System.Security.Claims;
using Govor.Domain;
using Microsoft.EntityFrameworkCore;
namespace Govor.API.Common.Extensions;
public static class SessionAuthorization
{
public static Task<bool> HasActiveSessionAsync(this GovorDbContext context, ClaimsPrincipal? user)
{
if (user?.Identity?.IsAuthenticated != true || user.FindFirst("tokenType")?.Value == "refresh" ||
!Guid.TryParse(user.FindFirst("userId")?.Value, out var userId) ||
!Guid.TryParse(user.FindFirst("sid")?.Value, out var sessionId))
return Task.FromResult(false);
var now = DateTime.UtcNow;
return context.UserSessions.AsNoTracking().AnyAsync(s => s.Id == sessionId &&
s.UserId == userId && !s.IsRevoked && s.ExpiresAt > now);
}
}