mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added user photo resizing
This commit is contained in:
@@ -7,6 +7,7 @@ using Berufsschule_HAM.Services;
|
||||
using ElmahCore;
|
||||
using Berufsschule_HAM.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Berufsschule_HAM.Helpers;
|
||||
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Route("[controller]")]
|
||||
@@ -82,9 +83,10 @@ public class HomeController : Controller
|
||||
List<UserTableViewModel> UserTableViewModels = [];
|
||||
foreach (UserModel user in users)
|
||||
{
|
||||
string photo = user.JpegPhoto is not null && user.JpegPhoto.Length > 0 ? ImageHelper.ResizeAndConvertToBase64(Convert.FromBase64String(user.JpegPhoto), 32) : "";
|
||||
UserTableViewModels.Add(new()
|
||||
{
|
||||
JpegPhoto = user.JpegPhoto ?? "",
|
||||
JpegPhoto = photo,
|
||||
Name = user.Cn ?? "",
|
||||
Surname = user.Sn ?? "",
|
||||
Title = user.Title ?? "",
|
||||
@@ -95,6 +97,24 @@ public class HomeController : Controller
|
||||
return View(new UsersIndexViewModel() { UserTableViewModels = UserTableViewModels });
|
||||
}
|
||||
|
||||
[Authorize(Roles = "CanManageUsers")]
|
||||
[HttpGet("UserPhoto")]
|
||||
public async Task<IActionResult> UserPhotoAsync(string uid, int? size)
|
||||
{
|
||||
UserModel? user = await _ldap.GetUserByUidAsync(uid, _ldap.UsersAttributes);
|
||||
if (user is null || user.JpegPhoto is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (size is null)
|
||||
{
|
||||
return File(Convert.FromBase64String(user.JpegPhoto), "image/jpeg");
|
||||
}
|
||||
string encodedFile = ImageHelper.ResizeAndConvertToBase64(Convert.FromBase64String(user.JpegPhoto), size ?? 32);
|
||||
return File(Convert.FromBase64String(encodedFile), "image/jpeg");
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Roles = "CanManageGroups")]
|
||||
[HttpGet("Groups")]
|
||||
public async Task<ActionResult> GroupsAsync()
|
||||
|
||||
Reference in New Issue
Block a user