diff --git a/Govor.API/Controllers/Authentication/SessionKeysController.cs b/Govor.API/Controllers/Authentication/SessionKeysController.cs index b001c70..d04fa75 100644 --- a/Govor.API/Controllers/Authentication/SessionKeysController.cs +++ b/Govor.API/Controllers/Authentication/SessionKeysController.cs @@ -1,3 +1,5 @@ +using Govor.Application.Interfaces.Infrastructure.Extensions; +using Govor.Contracts.Requests; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -9,9 +11,33 @@ namespace Govor.API.Controllers.Authentication; [Authorize(Roles = "Admin, User")] public class SessionKeysController : Controller { - // GET - public IActionResult Index() + private readonly ILogger _logger; + private readonly ICurrentUserSessionService _currentSession; + private readonly ICurrentUserService _currentUser; + /* + [HttpPost("keys")] + public async Task 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 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); + } + + */ } \ No newline at end of file diff --git a/Govor.Application/Interfaces/UserSession/ISessionKeyService.cs b/Govor.Application/Interfaces/UserSession/ISessionKeyService.cs new file mode 100644 index 0000000..76513b4 --- /dev/null +++ b/Govor.Application/Interfaces/UserSession/ISessionKeyService.cs @@ -0,0 +1,24 @@ +namespace Govor.Application.Interfaces.UserSession; + +public interface ISessionKeyService +{ + /// + /// Привязать публичные ключи текущего клиента к сессии. + /// + Task AttachKeysAsync(Guid userId, Guid sessionId, string publicEncryptionKey, string publicSigningKey); + + Task GetKeysAsync(Guid userId, Guid sessionId); + + /// + /// Получить публичные ключи пользователя (например, последнюю активную сессию или все активные). + /// + Task> 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; +} \ No newline at end of file diff --git a/Govor.Contracts/Requests/UploadKeysRequest.cs b/Govor.Contracts/Requests/UploadKeysRequest.cs new file mode 100644 index 0000000..c62cc78 --- /dev/null +++ b/Govor.Contracts/Requests/UploadKeysRequest.cs @@ -0,0 +1,7 @@ +namespace Govor.Contracts.Requests; + +public class UploadKeysRequest +{ + public string PublicEncryptionKey { get; set; } + public string PublicSigningKey { get; set; } +} \ No newline at end of file diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 145002e..8885cc7 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -4,26 +4,26 @@ ## Endpoints -* [Authentication](../endpoints/authentication/README.md) - * [AuthController](../endpoints/authentication/authcontroller.md) - * [RefreshController](../endpoints/authentication/refreshcontroller.md) -* [SessionController](endpoints/sessioncontroller.md) -* [FriendshipController](../endpoints/friendshipcontroller.md) -* [FriendsRequestQueryController](../endpoints/friendsrequestquerycontroller.md) -* [MediaController](../endpoints/mediacontroller.md) -* [ChatLoadController](../endpoints/chatloadcontroller.md) -* [OnlinePingingController(не работает)](../endpoints/onlinepingingcontroller-ne-rabotaet.md) +* [Authentication](../docs/endpoints/authentication/README.md) + * [AuthController](../docs/endpoints/authentication/authcontroller.md) + * [RefreshController](../docs/endpoints/authentication/refreshcontroller.md) +* [SessionController](../docs/endpoints/sessioncontroller.md) +* [FriendshipController](../docs/endpoints/friendshipcontroller.md) +* [FriendsRequestQueryController](../docs/endpoints/friendsrequestquerycontroller.md) +* [MediaController](../docs/endpoints/mediacontroller.md) +* [ChatLoadController](../docs/endpoints/chatloadcontroller.md) +* [OnlinePingingController(не работает)](../docs/endpoints/onlinepingingcontroller-ne-rabotaet.md) ## SignalR -* [PresenceHub](../signalr/presencehub.md) -* [ChatHub](../signalr/chathub.md) +* [PresenceHub](../docs/signalr/presencehub.md) +* [ChatHub](../docs/signalr/chathub.md) *** -* [FriendsHub](../friendshub/README.md) - * [FriendsHub Client (Java)](../friendshub/friendshub-client-java.md) +* [FriendsHub](../docs/friendshub/README.md) + * [FriendsHub Client (Java)](../docs/friendshub/friendshub-client-java.md) ## Code Docs -* [HubResult\](../code-docs/hubresult-less-than-t-greater-than.md) +* [HubResult\](../docs/code-docs/hubresult-less-than-t-greater-than.md)