This commit is contained in:
Artemy
2025-07-30 12:41:57 +07:00
parent 751c30dedd
commit dc560ba698
4 changed files with 74 additions and 17 deletions
@@ -1,3 +1,5 @@
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Contracts.Requests;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -9,9 +11,33 @@ namespace Govor.API.Controllers.Authentication;
[Authorize(Roles = "Admin, User")] [Authorize(Roles = "Admin, User")]
public class SessionKeysController : Controller public class SessionKeysController : Controller
{ {
// GET private readonly ILogger<SessionKeysController> _logger;
public IActionResult Index() private readonly ICurrentUserSessionService _currentSession;
private readonly ICurrentUserService _currentUser;
/*
[HttpPost("keys")]
public async Task<IActionResult> UploadSessionKeys([FromBody] UploadKeysRequest request)
{ {
return View(); var sessionId = _currentSession.GetUserSessionId();
await _sessionKeyService.AttachKeysAsync(sessionId, request.PublicEncryptionKey, request.PublicSigningKey);
return Ok();
} }
[Authorize]
[HttpGet("users/{userId}/keys")]
public async Task<IActionResult> GetUserPublicKeys(Guid userId)
{
var requesterId = _currentUserService.UserId;
if (!await _friendshipService.AreFriendsAsync(requesterId, userId))
return Forbid("You can only access keys of your friends");
var keys = await _sessionKeyService.GetAllActiveKeysAsync(userId);
return Ok(keys);
}
*/
} }
@@ -0,0 +1,24 @@
namespace Govor.Application.Interfaces.UserSession;
public interface ISessionKeyService
{
/// <summary>
/// Привязать публичные ключи текущего клиента к сессии.
/// </summary>
Task AttachKeysAsync(Guid userId, Guid sessionId, string publicEncryptionKey, string publicSigningKey);
Task<SessionPublicKeys?> GetKeysAsync(Guid userId, Guid sessionId);
/// <summary>
/// Получить публичные ключи пользователя (например, последнюю активную сессию или все активные).
/// </summary>
Task<IEnumerable<SessionPublicKeys>> GetAllActiveKeysAsync(Guid userId);
}
public class SessionPublicKeys
{
public Guid UserId { get; set; }
public Guid SessionId { get; set; }
public string PublicEncryptionKey { get; set; } = string.Empty;
public string PublicSigningKey { get; set; } = string.Empty;
}
@@ -0,0 +1,7 @@
namespace Govor.Contracts.Requests;
public class UploadKeysRequest
{
public string PublicEncryptionKey { get; set; }
public string PublicSigningKey { get; set; }
}
+14 -14
View File
@@ -4,26 +4,26 @@
## Endpoints ## Endpoints
* [Authentication](../endpoints/authentication/README.md) * [Authentication](../docs/endpoints/authentication/README.md)
* [AuthController](../endpoints/authentication/authcontroller.md) * [AuthController](../docs/endpoints/authentication/authcontroller.md)
* [RefreshController](../endpoints/authentication/refreshcontroller.md) * [RefreshController](../docs/endpoints/authentication/refreshcontroller.md)
* [SessionController](endpoints/sessioncontroller.md) * [SessionController](../docs/endpoints/sessioncontroller.md)
* [FriendshipController](../endpoints/friendshipcontroller.md) * [FriendshipController](../docs/endpoints/friendshipcontroller.md)
* [FriendsRequestQueryController](../endpoints/friendsrequestquerycontroller.md) * [FriendsRequestQueryController](../docs/endpoints/friendsrequestquerycontroller.md)
* [MediaController](../endpoints/mediacontroller.md) * [MediaController](../docs/endpoints/mediacontroller.md)
* [ChatLoadController](../endpoints/chatloadcontroller.md) * [ChatLoadController](../docs/endpoints/chatloadcontroller.md)
* [OnlinePingingController(не работает)](../endpoints/onlinepingingcontroller-ne-rabotaet.md) * [OnlinePingingController(не работает)](../docs/endpoints/onlinepingingcontroller-ne-rabotaet.md)
## SignalR ## SignalR
* [PresenceHub](../signalr/presencehub.md) * [PresenceHub](../docs/signalr/presencehub.md)
* [ChatHub](../signalr/chathub.md) * [ChatHub](../docs/signalr/chathub.md)
*** ***
* [FriendsHub](../friendshub/README.md) * [FriendsHub](../docs/friendshub/README.md)
* [FriendsHub Client (Java)](../friendshub/friendshub-client-java.md) * [FriendsHub Client (Java)](../docs/friendshub/friendshub-client-java.md)
## Code Docs&#x20; ## Code Docs&#x20;
* [HubResult\<T>](../code-docs/hubresult-less-than-t-greater-than.md) * [HubResult\<T>](../docs/code-docs/hubresult-less-than-t-greater-than.md)