mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Implements authentication system
This commit is contained in:
1 parent
38829d64ff
commit
a6dcf65d1c
103 files changed
+2983
-454
No files matched your search
@@ -3,6 +3,7 @@ using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Common.Models.Common;
|
||||
using Lumina.Presentation.Web.Common.Models.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,16 +26,19 @@ namespace Lumina.Presentation.Web.Common.Api;
|
||||
public class ApiHttpClient : IApiHttpClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly HttpContext? _httpContext;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiHttpClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">Injected HttpClient for interacting with the API.</param>
|
||||
/// <param name="httpContextAccessor">Injected service for providing the current HTTP context.</param>
|
||||
/// <param name="serverConfigurationOptions">Injected server configuration application settings.</param>
|
||||
public ApiHttpClient(HttpClient httpClient, IOptionsSnapshot<ServerConfigurationModel> serverConfigurationOptions)
|
||||
public ApiHttpClient(HttpClient httpClient, IHttpContextAccessor httpContextAccessor, IOptionsSnapshot<ServerConfigurationModel> serverConfigurationOptions)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_httpContext = httpContextAccessor.HttpContext;
|
||||
// read the API server configuration values from the configuration, and assign them to the injected client
|
||||
ServerConfigurationModel serverConfigurationModel = serverConfigurationOptions.Value;
|
||||
httpClient.BaseAddress = new Uri($"{serverConfigurationModel.BaseAddress}:{serverConfigurationModel.Port}/api/v{serverConfigurationModel.ApiVersion}/");
|
||||
@@ -52,14 +56,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
public async Task<TResponse> GetAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> GetAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -68,14 +72,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, string? token = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
// send the request and expect only headers initially - this prevents the client from buffering the entire response
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
@@ -93,14 +97,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A model containing the deserialized blob.</returns>
|
||||
public async Task<BlobDataModel> GetBlobAsync(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<BlobDataModel> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -125,14 +129,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the DELETE request.</returns>
|
||||
public async Task<TResponse> DeleteAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> DeleteAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Delete, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -143,14 +147,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and send to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
public async Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Put, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -162,14 +166,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
public async Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Post, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -203,4 +207,16 @@ public class ApiHttpClient : IApiHttpClient
|
||||
throw new ApiException(problemDetails, response.StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the authentication header for the current user, if available.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="AuthenticationHeaderValue"/> with a Bearer token if the user's token is found, <see langword="null"/> otherwise.
|
||||
/// </returns>
|
||||
private AuthenticationHeaderValue? GetAuthenticationHeader()
|
||||
{
|
||||
string? token = _httpContext?.User?.FindFirst("Token")?.Value;
|
||||
return !string.IsNullOrEmpty(token) ? new AuthenticationHeaderValue("Bearer", token) : null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -17,39 +17,35 @@ public interface IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
Task<TResponse> GetAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> GetAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result as a streamable response.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A model containing the deserialized blob.</returns>
|
||||
Task<BlobDataModel> GetBlobAsync(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<BlobDataModel> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a DELETE request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the DELETE request.</returns>
|
||||
Task<TResponse> DeleteAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> DeleteAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
@@ -58,10 +54,9 @@ public interface IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and send to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
@@ -70,8 +65,7 @@ public interface IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="InitializationRequirement"/> to ensure that the application is initialized before allowing authorization.
|
||||
/// </summary>
|
||||
public class InitializationHandler : AuthorizationHandler<InitializationRequirement>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializationHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected HTTP typed client for interactions with the API.</param>
|
||||
/// <param name="cache">Cache for storing the initialization status.</param>
|
||||
public InitializationHandler(IApiHttpClient apiHttpClient, IMemoryCache cache)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the application initialization status and authorizes the requirement if initialized.
|
||||
/// </summary>
|
||||
/// <param name="context">The authorization context.</param>
|
||||
/// <param name="requirement">The initialization requirement to be evaluated.</param>
|
||||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, InitializationRequirement requirement)
|
||||
{
|
||||
InitializationModel result = await _apiHttpClient.GetAsync<InitializationModel>("initialization/");
|
||||
HttpContext? httpContext = context.Resource as HttpContext;
|
||||
if (result.IsInitialized)
|
||||
{
|
||||
// admin account was registered, remove this requirement from the session
|
||||
httpContext?.Session.Remove(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP);
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
else // store in session that super admin setup is needed
|
||||
httpContext?.Session.SetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP, "true");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a requirement for initialization status in the authorization process.
|
||||
/// </summary>
|
||||
public class InitializationRequirement : IAuthorizationRequirement
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the timeout duration, in minutes, for caching the initialization check.
|
||||
/// </summary>
|
||||
public int CacheTimeoutMinutes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializationRequirement"/> class.
|
||||
/// </summary>
|
||||
/// <param name="cacheTimeoutMinutes">The cache timeout in minutes for the initialization status.</param>
|
||||
public InitializationRequirement(int cacheTimeoutMinutes = 5)
|
||||
{
|
||||
CacheTimeoutMinutes = cacheTimeoutMinutes;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class ApiExceptionFilter : IExceptionFilter
|
||||
if (context.Exception is ApiException apiException)
|
||||
{
|
||||
// handle unauthorized errors by prompting the user to re-login
|
||||
if (apiException.HttpStatusCode == HttpStatusCode.Unauthorized)
|
||||
if (apiException.HttpStatusCode == HttpStatusCode.Unauthorized) // HTTP 401 Unauthorized actually means lack of valid authentication credentials (not logged in)
|
||||
{
|
||||
SignOutSynchronously(context.HttpContext);
|
||||
string currentUrl = context.HttpContext.Request.GetDisplayUrl();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Filters;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute that enforces application initialization checks on controller actions.
|
||||
/// </summary>
|
||||
public class InitializationCheckAttribute : ActionFilterAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Asynchronously executes the initialization check before the action executes.
|
||||
/// </summary>
|
||||
/// <param name="context">The context for the action being executed.</param>
|
||||
/// <param name="next">Delegate to execute the next action filter in the pipeline.</param>
|
||||
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
IAuthorizationService authorizationService = context.HttpContext.RequestServices.GetRequiredService<IAuthorizationService>();
|
||||
await authorizationService.AuthorizeAsync(context.HttpContext.User, context.HttpContext, "RequireInitialization");
|
||||
await next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Lumina.Presentation.Web.Common.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Constants shared by HttpContext across a HTTP request (avoid magic strings).
|
||||
/// </summary>
|
||||
public static class HttpContextItemKeys
|
||||
{
|
||||
public const string ERRORS = "errors";
|
||||
public const string PENDING_SUPER_ADMIN_SETUP = "PendingSuperAdminSetup";
|
||||
}
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.MediaContributors;
|
||||
@@ -20,4 +19,4 @@ public class MediaContributorModel
|
||||
/// Gets the role of the contributor.
|
||||
/// </summary>
|
||||
public MediaContributorRoleModel? Role { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an item in a combobox.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The type used for the <see cref="Value"/> property of the item.</typeparam>
|
||||
[DebuggerDisplay("{Text}")]
|
||||
public class ComboboxItem<TValue>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the text of the item, that is visible to the user.
|
||||
/// </summary>
|
||||
public string? Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the item, that is used by the application.
|
||||
/// </summary>
|
||||
public TValue? Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the property indicating whether this element can be selected or not.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the request model for account password change.
|
||||
/// </summary>
|
||||
/// <param name="Username">The username of the account.</param>
|
||||
/// <param name="CurrentPassword">The current password of the account.</param>
|
||||
/// <param name="NewPassword">The new password of the account.</param>
|
||||
/// <param name="NewPasswordConfirm">The confirmation of the new password of the account.</param>
|
||||
public record ChangePasswordRequestModel(
|
||||
string? Username,
|
||||
string? CurrentPassword,
|
||||
string? NewPassword,
|
||||
string? NewPasswordConfirm
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response model for an account password change request.
|
||||
/// </summary>
|
||||
/// <param name="IsPasswordChanged">Whether the password was changed or not.</param>
|
||||
[DebuggerDisplay("IsPasswordChanged: {IsPasswordChanged}")]
|
||||
public record ChangePasswordResponseModel(
|
||||
bool IsPasswordChanged
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Model for verifying the initialization status of the application.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("IsInitialized: {IsInitialized}")]
|
||||
public class InitializationModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the application has been run before, and the super admin account has been created.
|
||||
/// </summary>
|
||||
public bool IsInitialized { get; set; }
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the request model for account password recovery.
|
||||
/// </summary>
|
||||
/// <param name="Username">The username of the account for which to recover the password.</param>
|
||||
/// <param name="TotpCode">The TOTP (Time-Based One-Time Password) code used to recover the password.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record RecoverPasswordRequestModel(
|
||||
string? Username,
|
||||
string? TotpCode
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response model for an account password reset request.
|
||||
/// </summary>
|
||||
/// <param name="IsPasswordReset">Whether the password was reset or not.</param>
|
||||
[DebuggerDisplay("IsPasswordReset: {IsPasswordReset}")]
|
||||
public record RecoverPasswordResponseModel(
|
||||
bool IsPasswordReset
|
||||
);
|
||||
@@ -14,9 +14,9 @@ namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
/// <param name="Use2fa">Indicates whether two-factor authentication (2FA) should be enabled for the new account.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record RegisterRequestModel(
|
||||
string? Username = null,
|
||||
string? Password = null,
|
||||
string? PasswordConfirm = null,
|
||||
string? RegistrationType = null,
|
||||
string? Username,
|
||||
string? Password,
|
||||
string? PasswordConfirm,
|
||||
string? RegistrationType,
|
||||
bool Use2fa = true
|
||||
);
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Models.MediaContributors;
|
||||
using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to add a book.
|
||||
/// </summary>
|
||||
public class AddBookRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the written content metadata of the book.
|
||||
/// </summary>
|
||||
public WrittenContentMetadataModel? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the format of the book (e.g., Hardcover, Paperback), if applicable.
|
||||
/// </summary>
|
||||
public BookFormat? Format { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the edition of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? Edition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the volume or book number in the series, if applicable.
|
||||
/// </summary>
|
||||
public int? VolumeNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the series name, if the book is part of a series.
|
||||
/// </summary>
|
||||
public BookSeriesModel? Series { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ASIN (Amazon Standard Identification Number) of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? ASIN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Goodreads ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? GoodreadsId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Library of Congress Control Number (LCCN) of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? LCCN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the OCLC Number (WorldCat identifier) of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? OCLCNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Open Library ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? OpenLibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the LibraryThing ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? LibraryThingId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Google Books ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? GoogleBooksId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Barnes & Noble ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? BarnesAndNobleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Apple Books ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? AppleBooksId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ISBN (International Standard Book Number) of the book.
|
||||
/// </summary>
|
||||
public List<IsbnModel>? ISBNs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of media contributors (actors, directors, etc) starring in this book.
|
||||
/// </summary>
|
||||
public List<MediaContributorModel>? Contributors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this book.
|
||||
/// </summary>
|
||||
public List<BookRatingModel>? Ratings { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user