mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adds authorization roles administrator dashboard
This commit is contained in:
1 parent
290af03c83
commit
1df31515fb
191 files changed
+6189
-806
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.Common;
|
||||
using Microsoft.Extensions.Caching.Hybrid;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
@@ -42,13 +43,19 @@ public class CachedAuthorizationHandler : DelegatingHandler
|
||||
if (!requestPath.EndsWith(AUTHORIZATION_ENDPOINT, StringComparison.OrdinalIgnoreCase))
|
||||
return await base.SendAsync(request, cancellationToken);
|
||||
// otherwise, check the hybrid cache to see if there is a cached authorization
|
||||
string response = await _hybridCache.GetOrCreateAsync(
|
||||
CachedResponseModel response = await _hybridCache.GetOrCreateAsync(
|
||||
AUTHORIZATION_ENDPOINT,
|
||||
async (cancellationToken) =>
|
||||
{
|
||||
// perform the actual API call if cache is empty or expired
|
||||
HttpResponseMessage result = await base.SendAsync(request, cancellationToken);
|
||||
return await result.Content.ReadAsStringAsync(cancellationToken);
|
||||
string content = await result.Content.ReadAsStringAsync(cancellationToken);
|
||||
// cache both status code and content
|
||||
return new CachedResponseModel
|
||||
{
|
||||
Content = content,
|
||||
StatusCode = result.StatusCode
|
||||
};
|
||||
},
|
||||
new HybridCacheEntryOptions()
|
||||
{
|
||||
@@ -56,9 +63,9 @@ public class CachedAuthorizationHandler : DelegatingHandler
|
||||
},
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
return new HttpResponseMessage(HttpStatusCode.OK)
|
||||
return new HttpResponseMessage(response.StatusCode)
|
||||
{
|
||||
Content = new StringContent(response)
|
||||
Content = new StringContent(response.Content)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ public interface IUrlService
|
||||
/// </summary>
|
||||
/// <param name="action">The action name within the controller.</param>
|
||||
/// <param name="controller">The controller name.</param>
|
||||
/// <param name="additionalRouteValues">Optional additional route values, like query parameters.</param>
|
||||
/// <returns>An absolute URL to the specified action.</returns>
|
||||
string? GetAbsoluteUrl(string action, string controller);
|
||||
string? GetAbsoluteUrl(string action, string controller, object? additionalRouteValues = null);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Services;
|
||||
@@ -36,8 +37,9 @@ public class UrlService : IUrlService
|
||||
/// </summary>
|
||||
/// <param name="action">The action name within the controller.</param>
|
||||
/// <param name="controller">The controller name.</param>
|
||||
/// <param name="additionalRouteValues">Optional additional route values, like query parameters.</param>
|
||||
/// <returns>An absolute URL to the specified action.</returns>
|
||||
public string? GetAbsoluteUrl(string action, string controller)
|
||||
public string? GetAbsoluteUrl(string action, string controller, object? additionalRouteValues = null)
|
||||
{
|
||||
HttpContext? httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext is null)
|
||||
@@ -48,16 +50,24 @@ public class UrlService : IUrlService
|
||||
ControllerActionDescriptor? controllerActionDescriptor = _actionDescriptorCollectionProvider
|
||||
.ActionDescriptors.Items
|
||||
.OfType<ControllerActionDescriptor>()
|
||||
.FirstOrDefault(ad =>
|
||||
ad.ControllerName.Equals(controller, StringComparison.OrdinalIgnoreCase) &&
|
||||
ad.ActionName.Equals(action, StringComparison.OrdinalIgnoreCase));
|
||||
.FirstOrDefault(controllerActionDescription =>
|
||||
controllerActionDescription.ControllerName.Equals(controller, StringComparison.OrdinalIgnoreCase) &&
|
||||
controllerActionDescription.ActionName.Equals(action, StringComparison.OrdinalIgnoreCase));
|
||||
if (controllerActionDescriptor is null)
|
||||
return null;
|
||||
// check if the route template contains {culture}
|
||||
string? routeTemplate = controllerActionDescriptor.AttributeRouteInfo?.Template;
|
||||
bool needsCulture = routeTemplate?.Contains("{culture}") == true;
|
||||
// merge culture and additional values
|
||||
RouteValueDictionary routeValues = [];
|
||||
if (needsCulture)
|
||||
routeValues.Add("culture", culture);
|
||||
if (additionalRouteValues is not null)
|
||||
foreach (PropertyInfo prop in additionalRouteValues.GetType().GetProperties())
|
||||
routeValues.Add(prop.Name, prop.GetValue(additionalRouteValues));
|
||||
|
||||
// create route values based on whether the controller is localized
|
||||
object values = needsCulture ? new { culture, action } : new { action };
|
||||
return _linkGenerator.GetUriByAction(httpContext: httpContext, action: action, controller: controller, values: values, scheme: scheme);
|
||||
return _linkGenerator.GetUriByAction(httpContext: httpContext, action: action, controller: controller, values: routeValues, scheme: scheme);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user