feat: добавил отображение аватарки
This commit is contained in:
1 parent
34e450815b
commit
038f0d89a6
22 files changed
+598
-28
No files matched your search
@@ -228,6 +228,8 @@ public class AuthController : ControllerBase
|
||||
var refreshToken = Request.Cookies["refreshToken"];
|
||||
if (!string.IsNullOrEmpty(refreshToken))
|
||||
await _auth.RevokeRefreshTokenAsync(refreshToken);
|
||||
var userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub") ?? "0");
|
||||
await _auth.RemoveMicrosoftTokenCacheAsync(userId);
|
||||
Response.Cookies.Delete("refreshToken");
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using UniVerse.Application.Interfaces;
|
||||
|
||||
namespace UniVerse.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/v1/users/me/photo")]
|
||||
public sealed class ProfilePhotoController : ControllerBase
|
||||
{
|
||||
private readonly IAuthService _auth;
|
||||
private readonly IMicrosoftAuthClient _microsoft;
|
||||
|
||||
public ProfilePhotoController(IAuthService auth, IMicrosoftAuthClient microsoft)
|
||||
{
|
||||
_auth = auth;
|
||||
_microsoft = microsoft;
|
||||
}
|
||||
|
||||
/// <summary>Получить фото текущего пользователя из Microsoft Entra.</summary>
|
||||
[HttpGet]
|
||||
[Produces("image/jpeg", "image/png", "image/gif", "image/webp")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub") ?? "0");
|
||||
await _auth.GetCurrentUserAsync(userId);
|
||||
Response.Headers.CacheControl = "private, no-store";
|
||||
var photo = await _microsoft.GetPhotoAsync(userId, cancellationToken);
|
||||
if (photo is null) return NotFound();
|
||||
return File(photo.Content, photo.ContentType);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user