mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Updates to .NET 9.0
This commit is contained in:
commit
acbdb0a5f8
853 files changed
+34993
-10123
No files matched your search
@@ -2,7 +2,8 @@
|
||||
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.FileManagement;
|
||||
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,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -1,13 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Utilities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Class containing the configuration bindings of the Lumina.Presentation.Web project.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal static class PresentationWebLayerConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
@@ -26,6 +30,12 @@ internal static class PresentationWebLayerConfiguration
|
||||
.Bind(configuration.GetRequiredSection(ServerConfigurationModel.SECTION_NAME))
|
||||
.ValidateFluently()
|
||||
.ValidateOnStart();
|
||||
|
||||
serviceCollection.AddOptions<EncryptionSettingsModel>()
|
||||
.Bind(configuration.GetRequiredSection(EncryptionSettingsModel.SECTION_NAME))
|
||||
.ValidateFluently()
|
||||
.ValidateOnStart();
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
}
|
||||
|
||||
+78
-3
@@ -1,18 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Common.Filters;
|
||||
using Lumina.Presentation.Web.Common.Security;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Polly;
|
||||
using Polly.CircuitBreaker;
|
||||
using Polly.Retry;
|
||||
using Polly.Wrap;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DependencyInjection;
|
||||
@@ -20,6 +29,7 @@ namespace Lumina.Presentation.Web.Common.DependencyInjection;
|
||||
/// <summary>
|
||||
/// Contains all services of the Presentation Web layer.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class PresentationWebLayerServices
|
||||
{
|
||||
/// <summary>
|
||||
@@ -30,13 +40,73 @@ public static class PresentationWebLayerServices
|
||||
public static IServiceCollection AddPresentationWebLayerServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddControllersWithViews(options => options.Filters.Add(typeof(ApiExceptionFilter)))
|
||||
.AddJsonOptions(options =>
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.MaxDepth = 256;
|
||||
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; // needed because file system API responses can have very nested structures
|
||||
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
});
|
||||
|
||||
// configure cookie-based authentication
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddCookie(options =>
|
||||
{
|
||||
// basic path configuration
|
||||
options.LoginPath = "/auth/login";
|
||||
options.LogoutPath = "/auth/logout";
|
||||
options.AccessDeniedPath = "/auth/access-denied";
|
||||
|
||||
// Cookie configuration
|
||||
options.Cookie = new CookieBuilder
|
||||
{
|
||||
Name = ".Lumina.Auth", // unique name to avoid conflicts
|
||||
HttpOnly = true, // prevent JavaScript access
|
||||
SameSite = SameSiteMode.Lax, // balance between security and functionality
|
||||
SecurePolicy = CookieSecurePolicy.Always, // require HTTPS
|
||||
Path = "/", // make cookie available for all paths
|
||||
IsEssential = true // mark as essential for GDPR
|
||||
};
|
||||
|
||||
// security settings
|
||||
options.ExpireTimeSpan = TimeSpan.FromHours(24); // TODO: perhaps make it configurable by user?
|
||||
options.SlidingExpiration = true;
|
||||
|
||||
// handle validation to support various deployment scenarios
|
||||
options.Events = new CookieAuthenticationEvents
|
||||
{
|
||||
// handle redirects to work with different base paths
|
||||
OnRedirectToLogin = context =>
|
||||
{
|
||||
// preserve any base path or subdirectory
|
||||
string redirectPath = context.RedirectUri;
|
||||
if (context.Request.PathBase.HasValue)
|
||||
redirectPath = context.Request.PathBase + options.LoginPath + new QueryString("?returnUrl=") + Uri.EscapeDataString(context.Request.PathBase + context.Request.Path);
|
||||
context.Response.Redirect(redirectPath);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// add an authorization policy that ensures application is initialized with super admin account before allowing access
|
||||
services.AddAuthorizationBuilder()
|
||||
.AddPolicy("RequireInitialization", policy => policy.Requirements.Add(new InitializationRequirement()));
|
||||
|
||||
// add forwarded headers middleware to handle reverse proxy scenarios
|
||||
services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost;
|
||||
options.KnownNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
});
|
||||
|
||||
// configure session management to maintain user-specific data across requests
|
||||
services.AddSession(options =>
|
||||
{
|
||||
options.IdleTimeout = TimeSpan.FromMinutes(30); // session expires after 30 minutes of inactivity
|
||||
options.Cookie.HttpOnly = true; // prevent JavaScript access to session cookie, for security
|
||||
options.Cookie.IsEssential = true; // mark session cookie as essential, for GDPR compliance
|
||||
});
|
||||
|
||||
// scan the current assembly for validators and register them to the DI container
|
||||
services.AddValidatorsFromAssemblyContaining<Program>(ServiceLifetime.Singleton);
|
||||
|
||||
@@ -57,13 +127,18 @@ public static class PresentationWebLayerServices
|
||||
|
||||
AsyncPolicyWrap<HttpResponseMessage> policy = Policy.WrapAsync(retryPolicy, circuitBreakerPolicy);
|
||||
|
||||
// register the typed client used for the API interaction
|
||||
// register the HTTP typed client used for the API interaction
|
||||
services.AddHttpClient<IApiHttpClient, ApiHttpClient>()
|
||||
.AddPolicyHandler(retryPolicy)
|
||||
.AddPolicyHandler(circuitBreakerPolicy);
|
||||
|
||||
services.AddScoped<INotificationService, NotificationService>();
|
||||
// enable access to the current HTTP context in non-controller classes
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddScoped<ApiExceptionFilter>();
|
||||
services.AddScoped<IAuthorizationHandler, InitializationHandler>();
|
||||
services.AddSingleton<ICryptographyService, CryptographyService>();
|
||||
services.AddSingleton<IUrlService, UrlService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
namespace Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the types of written content libraries.
|
||||
/// </summary>
|
||||
public enum WrittenContentType
|
||||
public enum WrittenContentType // TODO: to be removed?
|
||||
{
|
||||
/// <summary>
|
||||
/// A printed or written literary work.
|
||||
@@ -35,6 +35,11 @@ public enum WrittenContentType
|
||||
/// </summary>
|
||||
Magazine,
|
||||
|
||||
/// <summary>
|
||||
/// Periodical publication containing news.
|
||||
/// </summary>
|
||||
Newspaper,
|
||||
|
||||
/// <summary>
|
||||
/// A style of Japanese comic books and graphic novels.
|
||||
/// </summary>
|
||||
@@ -59,4 +64,4 @@ public enum WrittenContentType
|
||||
/// A script for a film, television program, or other visual media.
|
||||
/// </summary>
|
||||
Screenplay,
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Lumina.Presentation.Web.Common.Enums.Library;
|
||||
namespace Lumina.Presentation.Web.Common.Enums.Library;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the types of libraries.
|
||||
@@ -6,27 +6,182 @@
|
||||
public enum LibraryType
|
||||
{
|
||||
/// <summary>
|
||||
/// Content that is written, such as books, articles, or other written works.
|
||||
/// Traditional printed books in physical format.
|
||||
/// </summary>
|
||||
WrittenContent,
|
||||
Book,
|
||||
|
||||
/// <summary>
|
||||
/// Content that is video, such as movies, TV shows, or other video works.
|
||||
/// Digital books in electronic format (e.g., PDF, EPUB, MOBI).
|
||||
/// </summary>
|
||||
VideoContent,
|
||||
EBook,
|
||||
|
||||
/// <summary>
|
||||
/// Content that is audio, such as podcasts, radio shows, or other audio works.
|
||||
/// Comic books in digital or physical format.
|
||||
/// </summary>
|
||||
AudioContent,
|
||||
ComicBook,
|
||||
|
||||
/// <summary>
|
||||
/// Content that is visual, such as images, paintings, or other visual works.
|
||||
/// Periodical publications containing articles and illustrations.
|
||||
/// </summary>
|
||||
VisualContent,
|
||||
Magazine,
|
||||
|
||||
/// <summary>
|
||||
/// Content that is miscellaneous, such as lyrics, movie posters, or other miscellaneous works.
|
||||
/// Periodical publication containing news.
|
||||
/// </summary>
|
||||
MiscellaneousContent,
|
||||
}
|
||||
Newspaper,
|
||||
|
||||
/// <summary>
|
||||
/// Japanese-style comics and graphic novels.
|
||||
/// </summary>
|
||||
Manga,
|
||||
|
||||
/// <summary>
|
||||
/// Extended comic-format narratives, typically containing a complete story.
|
||||
/// </summary>
|
||||
GraphicNovel,
|
||||
|
||||
/// <summary>
|
||||
/// Scholarly articles and research papers.
|
||||
/// </summary>
|
||||
AcademicPaper,
|
||||
|
||||
/// <summary>
|
||||
/// Musical notation and scores.
|
||||
/// </summary>
|
||||
SheetMusic,
|
||||
|
||||
/// <summary>
|
||||
/// Television series and episodic content.
|
||||
/// </summary>
|
||||
TvShow,
|
||||
|
||||
/// <summary>
|
||||
/// Feature-length films and motion pictures.
|
||||
/// </summary>
|
||||
Movie,
|
||||
|
||||
/// <summary>
|
||||
/// Non-fiction films presenting factual information.
|
||||
/// </summary>
|
||||
Documentary,
|
||||
|
||||
/// <summary>
|
||||
/// Japanese animation series and films.
|
||||
/// </summary>
|
||||
Anime,
|
||||
|
||||
/// <summary>
|
||||
/// Recorded live music performances and concerts.
|
||||
/// </summary>
|
||||
ConcertVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Educational and instructional videos.
|
||||
/// </summary>
|
||||
TutorialVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Personally recorded videos and family footage.
|
||||
/// </summary>
|
||||
HomeVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Videos sourced from YouTube platform.
|
||||
/// </summary>
|
||||
YouTubeVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Professional or amateur music video productions.
|
||||
/// </summary>
|
||||
MusicVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Videos recorded during live performances or events.
|
||||
/// </summary>
|
||||
LiveRecordingVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Recorded conversations and Q&A sessions in video format.
|
||||
/// </summary>
|
||||
InterviewVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Videos of musical performances covering other artists' work.
|
||||
/// </summary>
|
||||
CoverSongVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Video format podcasts and episodic content.
|
||||
/// </summary>
|
||||
PodcastVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Audio recordings of musical content.
|
||||
/// </summary>
|
||||
Music,
|
||||
|
||||
/// <summary>
|
||||
/// Narrated books in audio format.
|
||||
/// </summary>
|
||||
Audiobook,
|
||||
|
||||
/// <summary>
|
||||
/// Audio recordings from live performances or events.
|
||||
/// </summary>
|
||||
LiveRecordingAudio,
|
||||
|
||||
/// <summary>
|
||||
/// Recorded conversations and Q&A sessions in audio format.
|
||||
/// </summary>
|
||||
InterviewAudio,
|
||||
|
||||
/// <summary>
|
||||
/// Audio recordings of musical performances covering other artists' work.
|
||||
/// </summary>
|
||||
CoverSongAudio,
|
||||
|
||||
/// <summary>
|
||||
/// Modified or reinterpreted versions of original musical recordings.
|
||||
/// </summary>
|
||||
Remix,
|
||||
|
||||
/// <summary>
|
||||
/// Audio clips used for sound design and production.
|
||||
/// </summary>
|
||||
SoundEffect,
|
||||
|
||||
/// <summary>
|
||||
/// Audio format podcasts and episodic content.
|
||||
/// </summary>
|
||||
PodcastAudio,
|
||||
|
||||
/// <summary>
|
||||
/// Digital images and photographs.
|
||||
/// </summary>
|
||||
Photo,
|
||||
|
||||
/// <summary>
|
||||
/// Curated sequences of media items.
|
||||
/// </summary>
|
||||
Playlist,
|
||||
|
||||
/// <summary>
|
||||
/// Grouped sets of related media items.
|
||||
/// </summary>
|
||||
Collection,
|
||||
|
||||
/// <summary>
|
||||
/// Text files containing dialogue translations for video content.
|
||||
/// </summary>
|
||||
Subtitles,
|
||||
|
||||
/// <summary>
|
||||
/// Text files containing words and timing for musical content.
|
||||
/// </summary>
|
||||
Lyrics,
|
||||
|
||||
/// <summary>
|
||||
/// A collection of media that does not fit into any other category.
|
||||
/// </summary>
|
||||
Other
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Model for deserializing media settings.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{SECTION_NAME}")]
|
||||
public class EncryptionSettingsModel
|
||||
{
|
||||
public const string SECTION_NAME = "EncryptionSettings";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the root directory where media files are stored.
|
||||
/// </summary>
|
||||
public required string SecretKey { get; init; }
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a model for storing binary data (blob).
|
||||
+1
-1
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Model for directories displayed in custom directory/file browser dialogs.
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Model for files displayed in custom directory/file browser dialogs.
|
||||
+1
-1
@@ -3,7 +3,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Base model for files and directories displayed in custom directory/file browser dialogs.
|
||||
+1
-1
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Generic file system node.
|
||||
+1
-1
@@ -3,7 +3,7 @@ using Lumina.Presentation.Web.Common.Enums.FileSystem;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Model containing the file system platform type.
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a response to the inquiry about the existence of a file system path.
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a response containing a file system path.
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// A model representing a file system path separator.
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a response to the inquiry about the validity of a file system path.
|
||||
+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; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the request model for user authentication.
|
||||
/// </summary>
|
||||
/// <param name="Username">The username used to authenticate.</param>
|
||||
/// <param name="Password">The password used to authenticate.</param>
|
||||
/// <param name="TotpCode">The TOTP (Time-Based One-Time Password) code used for two-factor authentication.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record LoginRequestModel(
|
||||
string? Username = null,
|
||||
string? Password = null,
|
||||
string? TotpCode = null
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response model for a user authentication.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the logged in user.</param>
|
||||
/// <param name="Username">The username of the logged in user.</param>
|
||||
/// <param name="Token">The JWT authentication token, <see langword="null"/> if authentication failed or TOTP is required.</param>
|
||||
/// <param name="UsesTotp">Indicates whether the user has Two-Factor Authentication enabled, or not.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record LoginResponseModel(
|
||||
Guid Id,
|
||||
string? Username,
|
||||
string? Token,
|
||||
bool UsesTotp
|
||||
);
|
||||
+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
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the request model for user registration.
|
||||
/// </summary>
|
||||
/// <param name="Username">The desired username for the new account.</param>
|
||||
/// <param name="Password">The password for the new account.</param>
|
||||
/// <param name="PasswordConfirm">The confirmation of the entered password, used to ensure consistency.</param>
|
||||
/// <param name="RegistrationType">Specifies the type of registration, e.g., "Admin" or "User".</param>
|
||||
/// <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,
|
||||
string? Password,
|
||||
string? PasswordConfirm,
|
||||
string? RegistrationType,
|
||||
bool Use2fa = true
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response model for a successful registration.
|
||||
/// </summary>
|
||||
/// <param name="Username">The username of the registered user.</param>
|
||||
/// <param name="TotpSecret">The TOTP (Time-Based One-Time Password) secret used for two-factor authentication.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record RegisterResponseModel(
|
||||
string? Username,
|
||||
string? TotpSecret
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a book.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Title}")]
|
||||
public class BooksModel
|
||||
{
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a preview of important properties of a book.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Title}")]
|
||||
public class LightBookModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the media item.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the media item.
|
||||
/// </summary>
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional release year (either re-release year, if available, or original release year, if known) of the media item.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional path of the image representing the cover of this book.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
}
|
||||
-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; }
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Security;
|
||||
|
||||
/// <summary>
|
||||
/// Service for cryptographic concerns.
|
||||
/// </summary>
|
||||
public sealed class CryptographyService : ICryptographyService, IDisposable
|
||||
{
|
||||
private readonly byte[] _key;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CryptographyService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="encryptionSettingsModelOptions">Injected service for retrieving <see cref="EncryptionSettingsModel"/>.</param>
|
||||
public CryptographyService(IOptions<EncryptionSettingsModel> encryptionSettingsModelOptions)
|
||||
{
|
||||
_key = Convert.FromBase64String(encryptionSettingsModelOptions.Value.SecretKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypts a plaintext string using AES encryption with a randomly generated initialization vector (IV).
|
||||
/// </summary>
|
||||
/// <param name="plaintext">The plaintext string to encrypt.</param>
|
||||
/// <returns>A Base64-encoded string of the combined IV and encrypted ciphertext.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="plaintext"/> is <see langword="null"/> or empty.</exception>
|
||||
public string Encrypt(string plaintext)
|
||||
{
|
||||
if (string.IsNullOrEmpty(plaintext))
|
||||
throw new ArgumentException("Value cannot be null or empty", nameof(plaintext));
|
||||
|
||||
// generate a new, random 16-byte IV for each encryption to ensure unique ciphertexts
|
||||
byte[] iv = new byte[16];
|
||||
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
|
||||
rng.GetBytes(iv);
|
||||
|
||||
using Aes aes = Aes.Create();
|
||||
aes.Key = _key;
|
||||
aes.IV = iv;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using ICryptoTransform encryptor = aes.CreateEncryptor();
|
||||
byte[] plaintextBytes = Encoding.UTF8.GetBytes(plaintext);
|
||||
byte[] ciphertext = encryptor.TransformFinalBlock(plaintextBytes, 0, plaintextBytes.Length);
|
||||
|
||||
// combine IV and ciphertext
|
||||
byte[] combined = new byte[iv.Length + ciphertext.Length];
|
||||
Buffer.BlockCopy(iv, 0, combined, 0, iv.Length);
|
||||
Buffer.BlockCopy(ciphertext, 0, combined, iv.Length, ciphertext.Length);
|
||||
|
||||
return Convert.ToBase64String(combined);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypts a Base64-encoded string that contains both the IV and ciphertext.
|
||||
/// </summary>
|
||||
/// <param name="ciphertext">The Base64-encoded string containing both IV and ciphertext.</param>
|
||||
/// <returns>The decrypted plaintext string.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="ciphertext"/> is <see langword="null"/>, empty, or invalid.</exception>
|
||||
public string Decrypt(string ciphertext)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ciphertext))
|
||||
throw new ArgumentException("Value cannot be null or empty", nameof(ciphertext));
|
||||
|
||||
// decode the combined data (IV + ciphertext) from Base64
|
||||
byte[] combined = Convert.FromBase64String(ciphertext);
|
||||
|
||||
if (combined.Length < 16)
|
||||
throw new ArgumentException("Invalid ciphertext");
|
||||
|
||||
// extract IV and ciphertext
|
||||
byte[] iv = new byte[16];
|
||||
byte[] encryptedData = new byte[combined.Length - 16];
|
||||
Buffer.BlockCopy(combined, 0, iv, 0, 16);
|
||||
Buffer.BlockCopy(combined, 16, encryptedData, 0, encryptedData.Length);
|
||||
|
||||
using Aes aes = Aes.Create();
|
||||
aes.Key = _key;
|
||||
aes.IV = iv;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using ICryptoTransform decryptor = aes.CreateDecryptor();
|
||||
byte[] decrypted = decryptor.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
|
||||
return Encoding.UTF8.GetString(decrypted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears sensitive key data when the service is disposed.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Array.Clear(_key, 0, _key.Length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Security;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service for cryptographic concerns.
|
||||
/// </summary>
|
||||
public interface ICryptographyService
|
||||
{
|
||||
/// <summary>
|
||||
/// Encrypts a plaintext string using AES encryption with a randomly generated initialization vector (IV).
|
||||
/// </summary>
|
||||
/// <param name="plaintext">The plaintext string to encrypt.</param>
|
||||
/// <returns>A Base64-encoded string of the combined IV and encrypted ciphertext.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="plaintext"/> is <see langword="null"/> or empty.</exception>
|
||||
string Encrypt(string plaintext);
|
||||
|
||||
/// <summary>
|
||||
/// Decrypts a Base64-encoded string that contains both the IV and ciphertext.
|
||||
/// </summary>
|
||||
/// <param name="ciphertext">The Base64-encoded string containing both IV and ciphertext.</param>
|
||||
/// <returns>The decrypted plaintext string.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="ciphertext"/> is <see langword="null"/>, empty, or invalid.</exception>
|
||||
string Decrypt(string ciphertext);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Notifications;
|
||||
using Lumina.Presentation.Web.Common.Models.Common;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service for showing notifications.
|
||||
/// </summary>
|
||||
public interface INotificationService
|
||||
{
|
||||
event Action<NotificationModel>? OnNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a notification.
|
||||
/// </summary>
|
||||
/// <param name="message">The message of the notification.</param>
|
||||
/// <param name="type">The type of the notification.</param>
|
||||
void Show(string message, NotificationType type);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Lumina.Presentation.Web.Common.Services;
|
||||
|
||||
public interface IUrlService
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an absolute URL for the specified controller action.
|
||||
/// </summary>
|
||||
/// <param name="action">The action name within the controller.</param>
|
||||
/// <param name="controller">The controller name.</param>
|
||||
/// <returns>An absolute URL to the specified action.</returns>
|
||||
string? GetAbsoluteUrl(string action, string controller);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Notifications;
|
||||
using Lumina.Presentation.Web.Common.Models.Common;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Service for showing notifications.
|
||||
/// </summary>
|
||||
public class NotificationService : INotificationService
|
||||
{
|
||||
public event Action<NotificationModel>? OnNotification;
|
||||
|
||||
/// <summary>
|
||||
/// Shows a notification.
|
||||
/// </summary>
|
||||
/// <param name="message">The message of the notification.</param>
|
||||
/// <param name="type">The type of the notification.</param>
|
||||
public void Show(string message, NotificationType type)
|
||||
{
|
||||
OnNotification?.Invoke(new NotificationModel { Message = message, Type = type, Id = Guid.NewGuid() });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Service for generating URLs from action and controller names.
|
||||
/// </summary>
|
||||
public class UrlService : IUrlService
|
||||
{
|
||||
private readonly LinkGenerator _linkGenerator;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UrlService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="linkGenerator">The ASP.NET Core link generator service.</param>
|
||||
/// <param name="httpContextAccessor">Provides access to the current HTTP context.</param>
|
||||
public UrlService(LinkGenerator linkGenerator, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_linkGenerator = linkGenerator;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an absolute URL for the specified controller action.
|
||||
/// </summary>
|
||||
/// <param name="action">The action name within the controller.</param>
|
||||
/// <param name="controller">The controller name.</param>
|
||||
/// <returns>An absolute URL to the specified action.</returns>
|
||||
public string? GetAbsoluteUrl(string action, string controller)
|
||||
{
|
||||
string? scheme = _httpContextAccessor.HttpContext?.Request.Scheme;
|
||||
return _linkGenerator.GetUriByAction(_httpContextAccessor.HttpContext!, action: action, controller: controller, values: null, scheme: scheme);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Presentation.Web.Common.Models.Configuration;
|
||||
using System;
|
||||
using System.Buffers.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for the EncryptionSettings application configuration settings section.
|
||||
/// </summary>
|
||||
public class EncryptionSettingsModelValidator : AbstractValidator<EncryptionSettingsModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EncryptionSettingsModelValidator"/> class.
|
||||
/// </summary>
|
||||
public EncryptionSettingsModelValidator()
|
||||
{
|
||||
RuleFor(x => x.SecretKey)
|
||||
.NotEmpty().WithMessage("Encryption secret key cannot be empty!")
|
||||
.Must(value => Base64.IsValid(value.AsSpan())).WithMessage("Encryption secret key must be a base64 string!");
|
||||
}
|
||||
}
|
||||
+9
-19
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,7 +9,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system directories.
|
||||
@@ -35,16 +35,11 @@ public class DirectoriesController : Controller
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-directories")]
|
||||
public async IAsyncEnumerable<DirectoryModel?> GetDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
IAsyncEnumerable<DirectoryModel?> response = _apiHttpClient.GetAsyncEnumerable<DirectoryModel>(
|
||||
IEnumerable<DirectoryModel> response = await _apiHttpClient.GetAsync<DirectoryModel[]>(
|
||||
$"directories/get-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
|
||||
await foreach (DirectoryModel? directory in response)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return directory;
|
||||
}
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,16 +49,11 @@ public class DirectoriesController : Controller
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-tree-directories")]
|
||||
public async IAsyncEnumerable<FileSystemTreeNodeModel?> GetTreeDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetTreeDirectories([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
IAsyncEnumerable<FileSystemTreeNodeModel?> response = _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>(
|
||||
IEnumerable<FileSystemTreeNodeModel> response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
|
||||
$"directories/get-tree-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
|
||||
await foreach (FileSystemTreeNodeModel? directory in response)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return directory;
|
||||
}
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,6 +66,6 @@ public class DirectoriesController : Controller
|
||||
public async Task<IActionResult> GetDirectoryTree([FromQuery] string path, [FromQuery] bool includeFiles, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
FileSystemTreeNodeModel[] response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>($"directories/get-directory-tree?path={Uri.EscapeDataString(path)}&includeFiles={includeFiles}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
|
||||
return Json(new { success = true, data = new { tree = response } });
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system drives.
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file systems.
|
||||
+9
-18
@@ -1,14 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system files.
|
||||
@@ -34,16 +35,11 @@ public class FilesController : Controller
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-tree-files")]
|
||||
public async IAsyncEnumerable<FileSystemTreeNodeModel?> GetTreeFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetTreeFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
IAsyncEnumerable<FileSystemTreeNodeModel?> response = _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>(
|
||||
IEnumerable<FileSystemTreeNodeModel> response = await _apiHttpClient.GetAsync<FileSystemTreeNodeModel[]>(
|
||||
$"files/get-tree-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
|
||||
await foreach (FileSystemTreeNodeModel? file in response)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return file;
|
||||
}
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,15 +49,10 @@ public class FilesController : Controller
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-files")]
|
||||
public async IAsyncEnumerable<FileModel?> GetFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetFiles([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
IAsyncEnumerable<FileModel?> response = _apiHttpClient.GetAsyncEnumerable<FileModel>(
|
||||
IEnumerable<FileModel> response = await _apiHttpClient.GetAsync<FileModel[]>(
|
||||
$"files/get-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
|
||||
await foreach (FileModel? file in response)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return file;
|
||||
}
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.FileManagement;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.FileManagement;
|
||||
namespace Lumina.Presentation.Web.Controllers.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system paths.
|
||||
@@ -1,14 +1,17 @@
|
||||
using Lumina.Presentation.Web.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers;
|
||||
|
||||
[Authorize]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Enums.Library;
|
||||
using Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.Library.Management;
|
||||
|
||||
[Route("/library/manage/")]
|
||||
public class LibraryManagementController : Controller
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
public LibraryManagementController(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View("/Views/Library/Management/Index.cshtml");
|
||||
}
|
||||
|
||||
[HttpGet("item/{id?}")]
|
||||
public IActionResult EditLibrary(Guid? id = null)
|
||||
{
|
||||
LibraryModel libraryModel = new()
|
||||
{
|
||||
Id = id,
|
||||
LibraryType = LibraryType.Book,
|
||||
Paths = ["a", "b", "c"],
|
||||
Title = ""
|
||||
};
|
||||
return View("/Views/Library/Management/Item.cshtml", libraryModel);
|
||||
}
|
||||
|
||||
[HttpPost("item")]
|
||||
public async Task<IActionResult> SaveLibraryAsync([FromBody] LibraryModel model)
|
||||
{
|
||||
LibraryModel response = model.Id.HasValue
|
||||
? await _apiHttpClient.PutAsync<LibraryModel, LibraryModel>($"libraries/{model.Id}", model)
|
||||
: await _apiHttpClient.PostAsync<LibraryModel, LibraryModel>("libraries", model);
|
||||
return Json(new { success = true });
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.Library.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
[Route("/library/written-content-library/books-library/books/")]
|
||||
public class BooksController : Controller
|
||||
{
|
||||
[HttpGet("")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml");
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult EditBook(Guid id)
|
||||
{
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Item.cshtml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Common.Filters;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Security;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for authentication related operations.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("/auth/")]
|
||||
public class AuthController : Controller
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
/// <param name="cryptographyService">Injected service for cryptographic functionality.</param>
|
||||
public AuthController(IApiHttpClient apiHttpClient, ICryptographyService cryptographyService)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_cryptographyService = cryptographyService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for registering a new account.
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[InitializationCheck]
|
||||
[HttpGet("register")]
|
||||
public IActionResult Register()
|
||||
{
|
||||
// check if this is the initial super admin setup
|
||||
string? isPendingSuperAdminSetup = HttpContext.Session.GetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP);
|
||||
ViewData["RegistrationType"] = isPendingSuperAdminSetup == "true" ? "Admin" : "User";
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for logging in.
|
||||
/// </summary>
|
||||
/// <param name="returnUrl">The url to return to, after login (if any).</param>
|
||||
[AllowAnonymous]
|
||||
[InitializationCheck]
|
||||
[HttpGet("login/{returnUrl?}")]
|
||||
public IActionResult Login(string? returnUrl = null)
|
||||
{
|
||||
ViewData["ReturnUrl"] = returnUrl;
|
||||
// if the user is already logged in, redirect them to the home page
|
||||
if (User?.Identity?.IsAuthenticated == true)
|
||||
return RedirectToAction("Index", "Home");
|
||||
// check if the application is initialized (does contain at least the super user account); if it's not, redirect to registration view
|
||||
string? isPendingSuperAdminSetup = HttpContext.Session.GetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP);
|
||||
if (isPendingSuperAdminSetup == "true")
|
||||
// TODO: should be:
|
||||
// return View("~/Views/Auth/Register", new RegisterRequestDto());
|
||||
// but doesn't work because of an ASP.NET bug: https://github.com/dotnet/AspNetCore.Docs/issues/25157
|
||||
return RedirectToAction("Register", "Auth");
|
||||
return View(new LoginRequestModel());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for recovering the password of an account.
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[InitializationCheck]
|
||||
[HttpGet("recover-password")]
|
||||
public IActionResult RecoverPassword()
|
||||
{
|
||||
// if the user is already logged in, redirect them to the home page
|
||||
if (User?.Identity?.IsAuthenticated == true)
|
||||
return RedirectToAction("Index", "Home");
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for changing the password of an account.
|
||||
/// </summary>
|
||||
[HttpGet("change-password")]
|
||||
public IActionResult ChangePassword()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for registering a new account.
|
||||
/// </summary>
|
||||
[HttpGet("profile")]
|
||||
public IActionResult Profile()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new account.
|
||||
/// </summary>
|
||||
/// <param name="data">User credentials used for registration.</param>
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
[HttpPost("register")]
|
||||
public async Task<IActionResult> Register([FromBody] RegisterRequestModel data)
|
||||
{
|
||||
// call different endpoints based on the view hidden field - registration for normal users, or initial application admin account setup
|
||||
string endpoint = data.RegistrationType == "Admin" ? "initialization" : "auth/register";
|
||||
// attempt API registration
|
||||
RegisterResponseModel response = await _apiHttpClient.PostAsync<RegisterResponseModel, RegisterRequestModel>(endpoint, data);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs in an account.
|
||||
/// </summary>
|
||||
/// <param name="data">User credentials used for login.</param>
|
||||
/// <param name="returnUrl">The url to return to, after login (if any).</param>
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
[HttpPost("login")]
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequestModel data, string? returnUrl = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// attempt API registration
|
||||
LoginResponseModel response = await _apiHttpClient.PostAsync<LoginResponseModel, LoginRequestModel>("auth/login", data);
|
||||
// store the received token in a secure cookie
|
||||
Response.Cookies.Delete("Token");
|
||||
Response.Cookies.Append("Token", _cryptographyService.Encrypt(response.Token!), new CookieOptions
|
||||
{
|
||||
Expires = DateTimeOffset.UtcNow.AddMonths(1),
|
||||
Path = "/",
|
||||
HttpOnly = true,
|
||||
Secure = true
|
||||
});
|
||||
// tell asp.net we are logged in
|
||||
List<Claim> claims =
|
||||
[
|
||||
new Claim(ClaimTypes.Name, response.Username!),
|
||||
new Claim(ClaimTypes.NameIdentifier, response.Id.ToString()!),
|
||||
new Claim("Token", response.Token!),
|
||||
];
|
||||
ClaimsIdentity claimsIdentity = new(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
// return success status and redirect URL
|
||||
return Json(new { success = true, data = string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl) ? Url.Content("~/") : Url.Content(returnUrl) });
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
// in this particular case, we DO NOT want to let the ApiExceptionFilter take care of this exception, because when the user has 2FA enabled, the first auth step involves sending
|
||||
// only the username and password, in which case the server API will respond with a validation error, that TOTP code is not valid (empty); it is then that we catch this error here
|
||||
// and display the form that asks the user for the TOTP code
|
||||
if (ex.ProblemDetails is not null && ex.ProblemDetails.Extensions?.Count > 0 && ex.ProblemDetails.Extensions.TryGetValue("errors", out JsonElement errorsObj))
|
||||
if (errorsObj is JsonElement jsonElement && jsonElement.ValueKind == JsonValueKind.Object)
|
||||
foreach (JsonProperty error in jsonElement.EnumerateObject())
|
||||
if (error.Value.ValueKind == JsonValueKind.Array)
|
||||
foreach (JsonElement errorValue in error.Value.EnumerateArray())
|
||||
if (errorValue.ValueKind == JsonValueKind.String && errorValue.GetString() == "InvalidTotpCode" && string.IsNullOrEmpty(data.TotpCode))
|
||||
return Json(new { success = true, data = new { isTotpRequired = true } }); // only get here when user did not enter a TOTP code at all, otherwise rethrow the validation error
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs out an account and redirects to the login page.
|
||||
/// </summary>
|
||||
[HttpGet("logout")]
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
// if the user is not logged in, redirect them to the home page
|
||||
if (User?.Identity?.IsAuthenticated == false)
|
||||
return RedirectToAction("Index", "Home");
|
||||
Response.Cookies.Delete("Token");
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
return RedirectToAction("Login", "Auth");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recovers the password of an account.
|
||||
/// </summary>
|
||||
/// <param name="data">User credentials used for password recovery.</param>
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
[HttpPost("recover-password")]
|
||||
public async Task<IActionResult> RecoverPassword([FromBody] RecoverPasswordRequestModel data)
|
||||
{
|
||||
RecoverPasswordResponseModel response = await _apiHttpClient.PostAsync<RecoverPasswordResponseModel, RecoverPasswordRequestModel>("auth/recover-password", data);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the password of an account.
|
||||
/// </summary>
|
||||
/// <param name="data">User credentials used for password change.</param>
|
||||
[ValidateAntiForgeryToken]
|
||||
[HttpPost("change-password")]
|
||||
public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordRequestModel data)
|
||||
{
|
||||
data = data with { Username = User?.Identity?.Name }; // assign the currently logged in user as the user for which to change the password
|
||||
ChangePasswordResponseModel response = await _apiHttpClient.PostAsync<ChangePasswordResponseModel, ChangePasswordRequestModel>("auth/change-password", data);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
RUN mkdir /logs && chown -R app:app /logs
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 5012
|
||||
|
||||
|
||||
# ==== Stage 1: Build stage
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages)
|
||||
COPY ["AssemblyInfo_Shared.cs", "."]
|
||||
COPY ["Lumina.Presentation.Web/Lumina.Presentation.Web.csproj", "Lumina.Presentation.Web/"]
|
||||
|
||||
RUN dotnet restore "./Lumina.Presentation.Web/Lumina.Presentation.Web.csproj" /p:BaseOutputPath=/app/publish/
|
||||
|
||||
# build the project
|
||||
COPY ["Lumina.Presentation.Web/", "Lumina.Presentation.Web/"]
|
||||
COPY . .
|
||||
WORKDIR /src/Lumina.Presentation.Web
|
||||
|
||||
RUN dotnet build "./Lumina.Presentation.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
||||
|
||||
# ==== Stage 2: Publish stage
|
||||
FROM build AS publish
|
||||
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
|
||||
RUN dotnet publish "./Lumina.Presentation.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:BaseOutputPath=/app/publish/
|
||||
|
||||
# ==== Stage 3: Run stage
|
||||
#FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
FROM base AS final
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=publish /app/publish .
|
||||
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||
EXPOSE 5012
|
||||
ENTRYPOINT ["dotnet", "Lumina.Presentation.Web.dll"]
|
||||
|
||||
# to build this Docker image, run the following command from the root of the project (location of the .sln file):
|
||||
# docker build --no-cache -t lumina-web -f Lumina.Presentation.Web/Dockerfile .
|
||||
@@ -3,9 +3,15 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\client\</BaseOutputPath>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\web\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
|
||||
<UserSecretsId>10a94da9-18ed-4c70-a9da-b461e08958c4</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<ContainerRepository>lumina-web</ContainerRepository>
|
||||
<DockerfileTag>lumina-web</DockerfileTag>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -15,10 +21,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation" Version="11.10.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.10.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0-rc.2.24473.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.0-rc.2.24474.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0-rc.2.24473.5" />
|
||||
<PackageReference Include="Polly" Version="8.4.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Polly" Version="8.5.0" />
|
||||
<PackageReference Include="Serilog" Version="4.1.1-dev-02318" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--disable warnings generated by Mediator source generator-->
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
@@ -11,6 +17,7 @@ namespace Lumina.Presentation.Web;
|
||||
/// <summary>
|
||||
/// Application entry point, contains the composition root module, wires up all dependencies of the application.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class Program
|
||||
{
|
||||
/// <summary>
|
||||
@@ -24,10 +31,37 @@ public class Program
|
||||
builder.Services.BindConfiguration(builder.Configuration);
|
||||
builder.Services.AddPresentationWebLayerServices();
|
||||
|
||||
// determine log path based on environment
|
||||
string logPath;
|
||||
if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true")
|
||||
{
|
||||
logPath = Environment.GetEnvironmentVariable("LOG_PATH") ?? "/logs"; // use docker volume path
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.ListenAnyIP(5012); // HTTP only
|
||||
});
|
||||
}
|
||||
else
|
||||
logPath = Path.Combine(AppContext.BaseDirectory, "logs"); // use local binary path
|
||||
Directory.CreateDirectory(logPath);
|
||||
if (!logPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
logPath = logPath += Path.DirectorySeparatorChar;
|
||||
// set environment variable for Serilog configuration
|
||||
Environment.SetEnvironmentVariable("LOG_PATH", logPath);
|
||||
|
||||
builder.Host.UseSerilog((context, services, configuration) =>
|
||||
{
|
||||
configuration.ReadFrom.Configuration(context.Configuration)
|
||||
.ReadFrom.Services(services)
|
||||
.Enrich.FromLogContext();
|
||||
});
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
app.UseSerilogRequestLogging();
|
||||
|
||||
// configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
if (!app.Environment.IsDevelopment() && Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") != "true")
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
@@ -36,14 +70,22 @@ public class Program
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseSession();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
// handle path base from reverse proxies
|
||||
app.Use((context, next) =>
|
||||
{
|
||||
if (context.Request.Headers.TryGetValue("X-Forwarded-Prefix", out StringValues pathBase))
|
||||
context.Request.PathBase = pathBase.ToString();
|
||||
return next();
|
||||
});
|
||||
|
||||
|
||||
app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
//"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5012",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5012"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
//"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5012;https://localhost:7112",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5012;https://localhost:7112"
|
||||
}
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
namespace Lumina.Presentation.Web.Renderers.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
public class BooksTemplateRenderer
|
||||
{
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class FileSystemBrowserViewComponent : ViewComponent
|
||||
{
|
||||
return View(new
|
||||
{
|
||||
Path = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? @"/" : @"C:\",
|
||||
Path = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? @"/" : @"C:\Users\",
|
||||
ServerBasePath = $"{_serverConfigurationModel.BaseAddress}:{_serverConfigurationModel.Port}/api/v{_serverConfigurationModel.ApiVersion}/",
|
||||
ClientBasePath = "http://localhost:5012/", // TODO: take from appsettings or environment
|
||||
ViewMode = FileSystemViewMode.List,
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
@*
|
||||
/auth/change-password/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model ChangePasswordRequestModel
|
||||
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
||||
<div class="shine-effect"></div>
|
||||
<form asp-controller="Auth" asp-action="ChangePassword" method="post" id="change-password-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="text" name="username" autocomplete="username" value="@User.Identity!.Name" hidden />
|
||||
<div class="form-container">
|
||||
<!-- Current Password -->
|
||||
<div class="form-row" id="div-current-password">
|
||||
<div class="form-label">
|
||||
<label asp-for="CurrentPassword">Current Password</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="CurrentPassword" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionCurrentPassword</small>
|
||||
</div>
|
||||
<!-- New Password -->
|
||||
<div class="form-row" id="div-new-password">
|
||||
<div class="form-label">
|
||||
<label asp-for="NewPassword">New Password</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="NewPassword" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionNewPassword</small>
|
||||
</div>
|
||||
<!-- New Password Confirm-->
|
||||
<div class="form-row" id="div-new-password-confirm">
|
||||
<div class="form-label">
|
||||
<label asp-for="NewPasswordConfirm">New Password Confirm</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="NewPasswordConfirm" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionNewPasswordConfirm</small>
|
||||
</div>
|
||||
<div class="form-row" id="div-change-password-submit" style="justify-content: center;">
|
||||
<button type="submit" class="confirm-button h-22px w-150px">Change Password</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="change-password-success" class="text-light-one w-100 hidden">Password Changed</p>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" defer>
|
||||
document.getElementById('change-password-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const txtCurrentPassword = form.querySelector('[name="CurrentPassword"]');
|
||||
const txtNewPassword = form.querySelector('[name="NewPassword"]');
|
||||
const txtNewPasswordConfirm = form.querySelector('[name="NewPasswordConfirm"]');
|
||||
|
||||
const changePasswordSuccess = document.getElementById('change-password-success');
|
||||
const divCurrentPassword = document.getElementById('div-current-password');
|
||||
const divNewPassword = document.getElementById('div-new-password');
|
||||
const divNewPasswordConfirm = document.getElementById('div-new-password-confirm');
|
||||
const divChangePasswordSubmit = document.getElementById('div-change-password-submit');
|
||||
|
||||
const formData = {
|
||||
CurrentPassword: txtCurrentPassword.value,
|
||||
NewPassword: txtNewPassword.value,
|
||||
NewPasswordConfirm: txtNewPasswordConfirm.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("ChangePassword", "Auth")', formData);
|
||||
if (data && data.isPasswordChanged === true) {
|
||||
changePasswordSuccess.classList.replace('hidden', 'block');
|
||||
divCurrentPassword.classList.add('hidden');
|
||||
divNewPassword.classList.add('hidden');
|
||||
divNewPasswordConfirm.classList.add('hidden');
|
||||
divChangePasswordSubmit.classList.add('hidden');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
@*
|
||||
/auth/login/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model LoginRequestModel
|
||||
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
||||
<div class="shine-effect"></div>
|
||||
<form asp-controller="Auth" asp-action="Login" method="post" id="login-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="ReturnUrl" value="@ViewData["ReturnUrl"]" />
|
||||
<div class="form-container">
|
||||
<!-- Username -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Username">Username</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="Username" autocomplete="username" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- Password -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Password">Password</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="Password" autocomplete="current-password" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button id="btn-recover-password" type="button" class="abort-button h-22px w-150px" data-link="@_urlService.GetAbsoluteUrl("RecoverPassword", "Auth")">Recover Password</button>
|
||||
<button id="btn-login" type="submit" class="confirm-button h-22px w-100px">Login</button>
|
||||
</div>
|
||||
<!-- 2FA -->
|
||||
<div class="form-row mt-10 hidden" id="div-totp-code">
|
||||
<div class="form-label">
|
||||
<label asp-for="TotpCode">Totp Code</label>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="number" asp-for="TotpCode" autocomplete="one-time-code" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button type="submit" id="btn-validate-totp" class="confirm-button h-22px w-100px hidden">Validate Code</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" defer>
|
||||
document.getElementById('login-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtPassword = form.querySelector('[name="Password"]');
|
||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||
const divTotpCode = document.getElementById('div-totp-code');
|
||||
const btnLogin = document.getElementById('btn-login');
|
||||
const btnRecoverPassword = document.getElementById('btn-recover-password');
|
||||
const btnValidateTotp = document.getElementById('btn-validate-totp');
|
||||
const formData = {
|
||||
Username: txtUsername.value,
|
||||
Password: txtPassword.value,
|
||||
TotpCode: txtTotpCode.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Login", "Auth")', formData);
|
||||
if (data && data.isTotpRequired === true) {
|
||||
txtUsername.disabled = true;
|
||||
txtPassword.disabled = true;
|
||||
btnLogin.disabled = true;
|
||||
btnRecoverPassword.disabled = true;
|
||||
divTotpCode.classList.replace('hidden', 'inline');
|
||||
btnValidateTotp.classList.replace('hidden', 'block');
|
||||
txtTotpCode.focus();
|
||||
}
|
||||
else if (data)
|
||||
window.location.href = data;
|
||||
});
|
||||
document.getElementById('btn-recover-password').addEventListener('click', () => {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl("RecoverPassword", "Auth")';
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
@*
|
||||
/auth/recover-password/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model RecoverPasswordRequestModel
|
||||
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
||||
<div class="shine-effect"></div>
|
||||
<form asp-controller="Auth" asp-action="RecoverPassword" method="post" id="recover-password-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<div class="form-container">
|
||||
<!-- Username -->
|
||||
<div class="form-row" id="div-username">
|
||||
<div class="form-label">
|
||||
<label asp-for="Username">Username</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="Username" autocomplete="username" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 2FA -->
|
||||
<div class="form-row" id="div-totp-code">
|
||||
<div class="form-label">
|
||||
<label asp-for="TotpCode">Totp Code</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="number" asp-for="TotpCode" autocomplete="one-time-code" class="enlightenment-input" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button id="btn-login" type="button" class="abort-button h-22px w-100px">Back To Login</button>
|
||||
<button type="submit" id="btn-validate-totp" class="confirm-button h-22px w-100px">Validate Code</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="recover-password-success" class="text-light-one w-100 hidden">Password Temporarily Reset</p>
|
||||
<button id="btn-redirect-login" type="submit" class="confirm-button h-22px w-80px hidden" data-link="@_urlService.GetAbsoluteUrl("Login", "Auth")">Login</button>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" defer>
|
||||
document.getElementById('recover-password-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||
const recoverPasswordSuccess = document.getElementById('recover-password-success');
|
||||
const btnRedirectLogin = document.getElementById('btn-redirect-login');
|
||||
const btnLogin = document.getElementById('btn-login');
|
||||
const btnValidateTotp = document.getElementById('btn-validate-totp');
|
||||
const divUsername = document.getElementById('div-username');
|
||||
const divTotpCode = document.getElementById('div-totp-code');
|
||||
|
||||
const formData = {
|
||||
Username: txtUsername.value,
|
||||
TotpCode: txtTotpCode.value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("RecoverPassword", "Auth")', formData);
|
||||
if (data && data.isPasswordReset === true) {
|
||||
divUsername.classList.add('hidden');
|
||||
btnValidateTotp.classList.add('hidden');
|
||||
btnLogin.classList.add('hidden');
|
||||
divTotpCode.classList.add('hidden');
|
||||
btnRedirectLogin.classList.replace('hidden', 'inline');
|
||||
recoverPasswordSuccess.classList.replace('hidden', 'block');
|
||||
}
|
||||
});
|
||||
document.getElementById('btn-login').addEventListener('click', () => {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl("Login", "Auth")';
|
||||
});
|
||||
document.getElementById('btn-redirect-login').addEventListener('click', () => {
|
||||
window.location.href = '@_urlService.GetAbsoluteUrl("Login", "Auth")';
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
@*
|
||||
/auth/register/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
|
||||
@{
|
||||
string? registrationType = ViewData["RegistrationType"] as string;
|
||||
}
|
||||
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model RegisterRequestModel
|
||||
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
||||
<div class="shine-effect"></div>
|
||||
<form asp-controller="Auth" asp-action="Register" method="post" id="register-account-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<!-- section for determining registration type (regular user/admin) -->
|
||||
<input type="hidden" name="RegistrationType" value="@registrationType" />
|
||||
<div class="form-container">
|
||||
@if (registrationType == "Admin")
|
||||
{
|
||||
<div class="form-row">
|
||||
<p class="invalid-feedback w-95 text-center f-18">Admin account registration</p>
|
||||
</div>
|
||||
}
|
||||
<!-- Username -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Username">Username</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="Username" autocomplete="username" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionUsername</small>
|
||||
</div>
|
||||
<!-- Password -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Password">Password</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="Password" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionPassword</small>
|
||||
</div>
|
||||
<!-- Password Confirm-->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="PasswordConfirm">Password Confirm</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input type="password" asp-for="PasswordConfirm" autocomplete="new-password" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionPasswordConfirm</small>
|
||||
</div>
|
||||
<!-- 2FA -->
|
||||
<input type="hidden" id="hidden-use-two-fa" name="use2fa" value="true">
|
||||
<div class="form-row">
|
||||
<div class="form-field">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" asp-for="Use2fa" class="enlightenment-checkbox-hidden" value="true" />
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
Enable two factor authentication
|
||||
</label>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">Description2Fa</small>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<span id="register-two-fa-attention" class="invalid-feedback w-95 text-center hidden">Password recovery is allowed only if two factor authentication is enabled!</span>
|
||||
</div>
|
||||
<div class="form-row" style="justify-content: center;">
|
||||
<button type="submit" class="confirm-button h-22px w-100px">Register</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="register-success" class="text-light-one w-100 hidden">Account Created</p>
|
||||
<img id="totp-image" class="w-200px h-200px h-align-m mx-auto mt-10 hidden" />
|
||||
<p id="totp-message" class="text-light-one w-100 hidden">Scan Totp Code</p>
|
||||
<button id="btn-login" type="button" class="confirm-button h-22px w-80px hidden" data-link="@_urlService.GetAbsoluteUrl("Login", "Auth")">Login</button>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" defer>
|
||||
document.getElementById('register-account-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtPassword = form.querySelector('[name="Password"]');
|
||||
const txtPasswordConfirm = form.querySelector('[name="PasswordConfirm"]');
|
||||
const chkUse2FA = form.querySelector('[name="Use2fa"]');
|
||||
const registerSuccess = document.getElementById('register-success');
|
||||
const btnLogin = document.getElementById('btn-login');
|
||||
const totpMessage = document.querySelector('#totp-message');
|
||||
const totpImage = document.querySelector('#totp-image');
|
||||
const formData = {
|
||||
Username: txtUsername.value,
|
||||
Password: txtPassword.value,
|
||||
PasswordConfirm: txtPasswordConfirm.value,
|
||||
Use2fa: chkUse2FA.checked,
|
||||
RegistrationType: form.querySelector('[name="RegistrationType"]').value
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Register", "Auth")', formData);
|
||||
if (data) {
|
||||
txtUsername.value = '';
|
||||
txtPassword.value = '';
|
||||
txtPasswordConfirm.value = '';
|
||||
form.classList.replace('inline', 'hidden');
|
||||
registerSuccess.classList.replace('hidden', 'inline');
|
||||
btnLogin.classList.replace('hidden', 'block');
|
||||
if (chkUse2FA.checked) {
|
||||
totpMessage.classList.remove('hidden');
|
||||
totpMessage.classList.add('block');
|
||||
|
||||
totpImage.classList.remove('hidden');
|
||||
totpImage.classList.add('block');
|
||||
totpImage.setAttribute('src', data.totpSecret);
|
||||
}
|
||||
}
|
||||
});
|
||||
document.querySelector('[name="Use2fa"]').addEventListener('change', function () {
|
||||
const isChecked = this.checked;
|
||||
document.getElementById('#register-two-fa-attention').classList.replace(
|
||||
isChecked ? 'inline' : 'hidden',
|
||||
isChecked ? 'hidden' : 'inline'
|
||||
);
|
||||
document.getElementById('#hidden-use-two-fa').value = isChecked.toString();
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
@*
|
||||
/library/manage/item/{id:guid}
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.Libraries
|
||||
|
||||
@{
|
||||
var id = Context.Request.RouteValues["id"] as string;
|
||||
}
|
||||
|
||||
@model LibraryModel
|
||||
|
||||
@await Component.InvokeAsync("FileSystemBrowser")
|
||||
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px; margin-top: 1rem;">
|
||||
<div class="shine-effect"></div>
|
||||
<form asp-controller="LibraryManagement" asp-action="EditLibrary" method="post" id="add-media-library-form">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Id" value="@id" />
|
||||
<div class="form-row">
|
||||
<h1 class="text-light-two w-100 text-center pt-0 pb-0 engraved-title">@(id is not null ? "Edit" : "Add New") Library</h1>
|
||||
</div>
|
||||
<div class="form-container">
|
||||
<h3 class="text-light-two">General Information</h3>
|
||||
<!-- Title -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="Title">Title</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="Title" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionTitle</small>
|
||||
</div>
|
||||
<!-- Library Type -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="LibraryType">Library Type</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<div class="enlightenment-combobox inline-block w-100">
|
||||
<div class="shine-effect" style="top: 1px;"></div>
|
||||
<input type="checkbox" class="enlightenment-toggle-checkbox" id="library-type" />
|
||||
<label class="enlightenment-toggle" for="library-type">
|
||||
<span class="enlightenment-selected-text">@Model.LibraryType</span>
|
||||
</label>
|
||||
<div class="enlightenment-dropdown">
|
||||
<div class="shine-effect" style="top: -4px;"></div>
|
||||
<!-- Dropdown options remain the same -->
|
||||
<div class="enlightenment-option first-option disabled">Book</div>
|
||||
<div class="enlightenment-option" data-value="Book">Book</div>
|
||||
<!-- ... rest of the options ... -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionLibraryType</small>
|
||||
</div>
|
||||
<!-- Directories -->
|
||||
<div class="form-row mt-10">
|
||||
<div class="form-label">
|
||||
<label asp-for="Paths">Directories</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
<img src="~/images/ui/add-directory.svg" alt="Add directory" id="add-media-directory" title="Add directory" class="add-form-table-row-icon ml-5" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-table w-100">
|
||||
@for (int i = 0; i < Model.Paths.Count; i++)
|
||||
{
|
||||
<div class="form-table-row">
|
||||
<span title="@Model.Paths[i]">@Model.Paths[i]</span>
|
||||
<img src="~/images/ui/delete.svg" alt="Remove" title="Remove" class="remove-form-table-row-icon" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">DescriptionDirectories</small>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button type="submit" class="confirm-button w-100px">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" defer>
|
||||
document.getElementById('add-media-directory').addEventListener('click', function () {
|
||||
showFileSystemBrowserDialogAsync('C:\\Users\\', true, false, addNewPaths); // TODO: take path and include hidden elements from settings
|
||||
});
|
||||
|
||||
function addNewPaths(selectedPaths) {
|
||||
// get the form table where the new paths will be added
|
||||
const formTable = document.querySelector('.form-table');
|
||||
// process the selected paths
|
||||
const paths = selectedPaths.slice(1, -1).split('","');
|
||||
// add each path as a new row
|
||||
paths.forEach(path => {
|
||||
// check if path already exists
|
||||
const existingPath = formTable.querySelector(`span[title="${path}"]`);
|
||||
if (!existingPath) {
|
||||
formTable.insertAdjacentHTML('beforeend', `
|
||||
<div class="form-table-row">
|
||||
<span title="${path}">${path}</span>
|
||||
<img src="/images/ui/delete.svg" alt="Remove" title="Remove" class="remove-form-table-row-icon" onclick="this.closest('.form-table-row').remove();" />
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('add-media-library-form').addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const formData = {
|
||||
Id: form.querySelector('[name="Id"]').value || null,
|
||||
Title: form.querySelector('[name="Title"]').value,
|
||||
LibraryType: form.querySelector('.enlightenment-selected-text').textContent,
|
||||
Paths: Array.from(form.querySelectorAll('.form-table-row span'))
|
||||
.map(span => span.textContent)
|
||||
};
|
||||
const result = await callApiPostAsync('/library/manage/item', formData);
|
||||
if (result) {
|
||||
// Optional: Handle successful response
|
||||
// For example, redirect after success
|
||||
// window.location.href = '/library/manage';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
<p>All books</p><a href="books/E6B599D6-3819-4FAB-B988-8F027072CF7B" class="nav-link">one</a>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<p>A book</p>
|
||||
+8
-13
@@ -3,16 +3,11 @@
|
||||
@using Lumina.Presentation.Web.Common.Enums.FileSystem
|
||||
@using Lumina.Presentation.Web.Common.Enums.Notifications
|
||||
@using Lumina.Presentation.Web.Common.Exceptions
|
||||
@using Lumina.Presentation.Web.Common.Models.FileManagement
|
||||
@using Lumina.Presentation.Web.Common.Models.UI
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Lumina.Presentation.Web.Common.Models.FileSystemManagement
|
||||
@using Microsoft.AspNetCore.Components
|
||||
@using System.Text.Json
|
||||
@using System.Text
|
||||
|
||||
@inject IApiHttpClient _apiHttpClient
|
||||
@inject INotificationService _notificationService
|
||||
|
||||
<div id="file-system-browser-dialog" class="container-background above-modal">
|
||||
<div id="file-system-browser-content">
|
||||
<div id="file-system-browser-header">
|
||||
@@ -309,9 +304,9 @@
|
||||
<div id="navigator-navigation-controls-container">
|
||||
<!--Navigation-->
|
||||
<div id="navigator-history">
|
||||
<img src="images/ui/back.svg" id="navigator-navigate-back" class="navigation-icon" alt="Back" title="Back" />
|
||||
<img src="images/ui/forward.svg" id="navigator-navigate-forward" class="navigation-icon" alt="Forward" title="Forward" />
|
||||
<img src="images/ui/up.svg" id="navigator-navigate-up" class="navigation-icon" alt="Up One Level" title="Up One Level" />
|
||||
<img src="~/images/ui/back.svg" id="navigator-navigate-back" class="navigation-icon" alt="Back" title="Back" />
|
||||
<img src="~/images/ui/forward.svg" id="navigator-navigate-forward" class="navigation-icon" alt="Forward" title="Forward" />
|
||||
<img src="~/images/ui/up.svg" id="navigator-navigate-up" class="navigation-icon" alt="Up One Level" title="Up One Level" />
|
||||
</div>
|
||||
<!--Toggle Tree View-->
|
||||
<svg id="navigator-toggle-tree-view-button" class="navigator-icon" width="30" height="30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
@@ -469,16 +464,16 @@
|
||||
</div>
|
||||
</div>
|
||||
<button id="navigator-edit-path-button" class="navigator-edit-path-button abort-button f-16" style="height:28px; width:35px;">
|
||||
<img src="images/ui/edit.svg" id="navigator-edit-icon" alt="Edit Path" title="Edit Path" />
|
||||
<img src="~/images/ui/edit.svg" id="navigator-edit-icon" alt="Edit Path" title="Edit Path" />
|
||||
</button>
|
||||
<button id="navigator-navigate-button" class="navigator-navigate-button confirm-button f-16" style="height:28px; width:35px;">
|
||||
<img src="images/ui/check.svg" id="navigator-navigate-icon" alt="Navigate" title="Navigate" />
|
||||
<img src="~/images/ui/check.svg" id="navigator-navigate-icon" alt="Navigate" title="Navigate" />
|
||||
</button>
|
||||
<button class="file-system-browser-content-new-directory abort-button f-16" style="height:28px; width:35px;">
|
||||
<img src="images/ui/new-directory.svg" id="navigator-new-directory-icon" alt="New Directory" title="New Directory" />
|
||||
<img src="~/images/ui/new-directory.svg" id="navigator-new-directory-icon" alt="New Directory" title="New Directory" />
|
||||
</button>
|
||||
<button class="file-system-browser-content-favorite-directory abort-button f-16" style="height:28px; width:35px;">
|
||||
<img src="images/ui/favorite-star.svg" class="navigation-icon favorite-unselected" alt="Favorite directory" title="Favorite directory" />
|
||||
<img src="~/images/ui/favorite-star.svg" class="navigation-icon favorite-unselected" alt="Favorite directory" title="Favorite directory" />
|
||||
</button>
|
||||
</div>
|
||||
<!--End File System Navigator-->
|
||||
|
||||
@@ -1,36 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Lumina</title>
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/button.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/checkbox.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/combobox.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/file-system-browser.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/file-system-tree-view-node.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/navigation-menu.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/notification.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/textbox.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/Lumina.Presentation.Web.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<header>
|
||||
@await Html.PartialAsync("_NavMenu")
|
||||
</header>
|
||||
<main role="main">
|
||||
<article>
|
||||
@RenderBody()
|
||||
</article>
|
||||
</main>
|
||||
</div>
|
||||
<!--Modal grid background-->
|
||||
<div id="modal-background"></div>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Lumina</title>
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/button.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/checkbox.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/combobox.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/file-system-browser.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/file-system-tree-view-node.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/navigation-menu.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/notification.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/textbox.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/Lumina.Presentation.Web.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<header>
|
||||
@await Html.PartialAsync("_NavMenu")
|
||||
</header>
|
||||
<main role="main" style="@(User?.Identity?.IsAuthenticated == false ? "bottom: 0px;" : string.Empty)">
|
||||
<article>
|
||||
@RenderBody()
|
||||
<div id="modal-background-article"></div>
|
||||
</article>
|
||||
</main>
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
|
||||
<script defer src="~/js/notifications.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
{
|
||||
<!--Audio player-->
|
||||
<div class="audio-player-container">
|
||||
<video controls
|
||||
preload="auto"
|
||||
height="50" width="600">
|
||||
<source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
|
||||
</video>
|
||||
<a id="audio-player-full-height-toggle">Toggle Full Height</a>
|
||||
<a id="audio-player-close">Toggle Visibility</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<!--Modal grid background-->
|
||||
<div id="modal-background-menu"></div>
|
||||
|
||||
<script defer src="~/js/notifications.js" asp-append-version="true"></script>
|
||||
<script defer src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
|
||||
@inject IUrlService _urlService
|
||||
|
||||
<input type="checkbox" id="hamburger-input" class="burger-shower" />
|
||||
<label id="hamburger-menu" for="hamburger-input">
|
||||
<span></span>
|
||||
@@ -9,45 +13,59 @@
|
||||
Account
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="account/login"><span>Login</span></a></li>
|
||||
<li><a href="account/logout"><span>Logout</span></a></li>
|
||||
<li><a href="account/register"><span>Register</span></a></li>
|
||||
<li><a href="account"><span>My Account</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Tools
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="tools/options"><span>Options</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Library
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/manage"><span>Manage libraries</span></a></li>
|
||||
<li><a href="library/manage/item"><span>Add media library</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Written Content
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/written-content/books"><span>Books</span></a></li>
|
||||
<li><a href="library/written-content/magazines"><span>Magazines</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Audio
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/audio/music"><span>Music</span></a></li>
|
||||
<li><a href="library/audio/interviews"><span>Interviews</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Video
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/video/movies"><span>Movies</span></a></li>
|
||||
<li><a href="library/video/tvshows"><span>TV Shows</span></a></li>
|
||||
@if (User?.Identity?.IsAuthenticated == false)
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Login", "Auth")"><span>Login</span></a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Login", "Auth")"><span>Recover Password</span></a></li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Logout", "Auth")"><span>Logout</span></a></li>
|
||||
}
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Login", "Auth")"><span>Register</span></a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Login", "Auth")"><span>Change Password</span></a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Login", "Auth")"><span>Profile</span></a></li>
|
||||
}
|
||||
</ul>
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
<div class="mobile-menu-heading">
|
||||
Tools
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="tools/options"><span>Options</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Library
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/manage"><span>Manage libraries</span></a></li>
|
||||
<li><a href="library/manage/item"><span>Add media library</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Written Content
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/written-content-library/books-library/books" class="nav-link"><span>Books</span></a></li>
|
||||
<li><a href="library/written-content/magazines"><span>Magazines</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Audio
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/audio/music"><span>Music</span></a></li>
|
||||
<li><a href="library/audio/interviews"><span>Interviews</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
Video
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="library/video/movies"><span>Movies</span></a></li>
|
||||
<li><a href="library/video/tvshows"><span>TV Shows</span></a></li>
|
||||
</ul>
|
||||
}
|
||||
<div class="mobile-menu-heading">
|
||||
Help
|
||||
</div>
|
||||
@@ -64,48 +82,62 @@
|
||||
<input type="radio" id="account-menu" name="menu">
|
||||
<label for="account-menu">Account</label>
|
||||
<ul>
|
||||
<li><a href="account/login">Login</a></li>
|
||||
<li><a href="account/logout">Logout</a></li>
|
||||
<li><a href="account/register">Register</a></li>
|
||||
<li><a href="account">My Account</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li tabindex="0">
|
||||
<input type="radio" id="tools-menu" name="menu">
|
||||
<label for="tools-menu">Tools</label>
|
||||
<ul>
|
||||
<li><a href="tools/options">Options</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li tabindex="0">
|
||||
<input type="radio" id="library-menu" name="menu">
|
||||
<label for="library-menu">Library</label>
|
||||
<ul>
|
||||
<li tabindex="0"><a href="library/manage">Manage libraries</a></li>
|
||||
<li tabindex="0"><a href="library/manage/item">Add new library</a></li>
|
||||
<li class="has-submenu" tabindex="0">
|
||||
<label>Written Content</label>
|
||||
<ul>
|
||||
<li><a href="library/written-content/books">Books</a></li>
|
||||
<li><a href="library/written-content/magazines">Magazines</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-submenu" tabindex="0">
|
||||
<label>Audio</label>
|
||||
<ul>
|
||||
<li><a href="library/audio/music">Music</a></li>
|
||||
<li><a href="library/audio/interviews">Interviews</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-submenu" tabindex="0">
|
||||
<label>Video</label>
|
||||
<ul>
|
||||
<li><a href="library/video/movies">Movies</a></li>
|
||||
<li><a href="library/video/tvshows">TV Shows</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@if (User?.Identity?.IsAuthenticated == false)
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Login", "Auth")">Login</a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("RecoverPassword", "Auth")">Recover Password</a></li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Logout", "Auth")">Logout</a></li>
|
||||
}
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Register", "Auth")">Register</a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("ChangePassword", "Auth")">Change Password</a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Profile", "Auth")">Profile</a></li>
|
||||
}
|
||||
</ul>
|
||||
</li>
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
<li tabindex="0">
|
||||
<input type="radio" id="tools-menu" name="menu">
|
||||
<label for="tools-menu">Tools</label>
|
||||
<ul>
|
||||
<li><a href="tools/options">Options</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li tabindex="0">
|
||||
<input type="radio" id="library-menu" name="menu">
|
||||
<label for="library-menu">Library</label>
|
||||
<ul>
|
||||
<li tabindex="0"><a href="library/manage">Manage libraries</a></li>
|
||||
<li tabindex="0"><a href="library/manage/item">Add new library</a></li>
|
||||
<li class="has-submenu" tabindex="0">
|
||||
<label>Written Content</label>
|
||||
<ul>
|
||||
<li><a href="library/written-content-library/books-library/books" class="nav-link">Books</a></li>
|
||||
<li><a href="library/written-content/magazines">Magazines</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-submenu" tabindex="0">
|
||||
<label>Audio</label>
|
||||
<ul>
|
||||
<li><a href="library/audio/music">Music</a></li>
|
||||
<li><a href="library/audio/interviews">Interviews</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-submenu" tabindex="0">
|
||||
<label>Video</label>
|
||||
<ul>
|
||||
<li><a href="library/video/movies">Movies</a></li>
|
||||
<li><a href="library/video/tvshows">TV Shows</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
}
|
||||
<li tabindex="0">
|
||||
<input type="radio" id="help-menu" name="menu">
|
||||
<label for="help-menu">Help</label>
|
||||
|
||||
@@ -1,8 +1,51 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"EncryptionSettings": {
|
||||
"SecretKey": "" // base64 string
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"System": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"Microsoft.AspNetCore.Mvc.Razor": "Error",
|
||||
"Microsoft.AspNetCore.Mvc.RazorPages": "Error"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Literate, Serilog.Sinks.Console",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "%LOG_PATH%lumina_web_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
|
||||
"retainedFileCountLimit": 7,
|
||||
"fileSizeLimitBytes": 10485760,
|
||||
"rollOnFileSizeLimit": true,
|
||||
"shared": true,
|
||||
"flushToDiskInterval": "00:00:01"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"FromLogContext",
|
||||
"WithMachineName",
|
||||
"WithThreadId",
|
||||
"WithEnvironmentName",
|
||||
"WithRequestId"
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "LuminaWeb"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
namespace Lumina.Presentation.Web.wwwroot.css
|
||||
{
|
||||
public class checkbox
|
||||
{
|
||||
}
|
||||
/* Basic styles for the label and the hidden checkbox */
|
||||
.enlightenment-checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #6DCBFE;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.enlightenment-checkbox-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Custom checkbox appearance */
|
||||
.enlightenment-checkbox {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-top: #000000 1px solid;
|
||||
border-bottom: #333333 1px solid;
|
||||
border-left: #000000 1px solid;
|
||||
border-right: #333333 1px solid;
|
||||
border-radius: 0;
|
||||
margin-right: 10px;
|
||||
position: relative;
|
||||
background: linear-gradient(to bottom, #111, #222 50%, #333);
|
||||
}
|
||||
|
||||
/* Update the custom checkbox appearance when checked */
|
||||
.enlightenment-checkbox-hidden:checked + .enlightenment-checkbox {
|
||||
background-image: linear-gradient(180deg, #5E5D5D, #505050, #424343);
|
||||
border-top: #888888 1px solid;
|
||||
border-bottom: #333333 1px solid;
|
||||
border-left: #666666 1px solid;
|
||||
border-right: #444444 1px solid;
|
||||
}
|
||||
@@ -10,6 +10,16 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.enlightenment-toggle-checkbox:checked + .enlightenment-toggle + .enlightenment-dropdown {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.enlightenment-toggle-checkbox:checked + .enlightenment-toggle .enlightenment-arrow {
|
||||
background-size: 9px 11px;
|
||||
background-position: 3px -2px;
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.enlightenment-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -44,6 +54,21 @@
|
||||
background-size: 12px 6px, 3px auto, 100%;
|
||||
}
|
||||
|
||||
.enlightenment-arrow {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 9px;
|
||||
background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%22545%20-32.5%2027.5%2065%22%3E%3Cpath%20fill%3D%22%23FFF%22%20d%3D%22M568.254,-7.43524%20568.159,-7.34277%20567.977,-7.52246%20546.559,-28.9417%20525.484,-28.9417%20549.787,-4.63446%20557.439,3.01532%20557.619,3.19629%20550.067,10.7549%20525.758,35.0583%20546.834,35.0583%20568.254,13.6429%20578.792,3.10254%20568.254,-7.43524z%22%2F%3E%3C%2Fsvg%3E');
|
||||
background-size: 10px 9px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 3px -0px;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.enlightenment-toggle-checkbox:checked + .enlightenment-toggle .enlightenment-arrow {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.enlightenment-selected-text {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
@@ -66,15 +91,9 @@
|
||||
border-right: #202020 1px solid;
|
||||
padding: 3px;
|
||||
z-index: 999;
|
||||
max-height: none;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.enlightenment-dropdown > .shine-effect:first-child {
|
||||
top: -4px;
|
||||
}
|
||||
|
||||
.enlightenment-item {
|
||||
.enlightenment-option {
|
||||
display: block;
|
||||
border-left: 1px solid #232323;
|
||||
border-right: 1px solid #777777;
|
||||
@@ -88,32 +107,30 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.enlightenment-item.first-item {
|
||||
.enlightenment-option.first-option {
|
||||
border-top: 1px solid #232323;
|
||||
margin-top: -1px;
|
||||
}
|
||||
|
||||
.enlightenment-item.last-item {
|
||||
.enlightenment-option.last-option {
|
||||
border-bottom: 1px solid #777777;
|
||||
}
|
||||
|
||||
.enlightenment-item.disabled {
|
||||
color: #AAAAAA;
|
||||
.enlightenment-option.disabled {
|
||||
color: #AAAAAA; /* Gray color */
|
||||
}
|
||||
|
||||
.enlightenment-item:hover {
|
||||
.enlightenment-option:hover {
|
||||
background-image: none;
|
||||
background: linear-gradient(to bottom, #505050, #464646, #404040, #363636);
|
||||
color: #1D8AF9;
|
||||
box-shadow: inset 1px 0 0 0 #777777, inset -1px 0 0 0 #232323, inset 0 1px 0 0 #989898, inset 0 -1px 0 0 #151515;
|
||||
box-shadow: inset 1px 0 0 0 #777777, /* left */
|
||||
inset -1px 0 0 0 #232323, /* right */
|
||||
inset 0 1px 0 0 #989898, /* top */
|
||||
inset 0 -1px 0 0 #151515; /* bottom */
|
||||
}
|
||||
|
||||
.enlightenment-combobox.open .enlightenment-dropdown {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.enlightenment-combobox > .shine-effect:first-child {
|
||||
top: 1px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.5s;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#file-system-browser-dialog {
|
||||
display: none;
|
||||
position: absolute;
|
||||
position: fixed;
|
||||
top: 12.5%;
|
||||
bottom: 12.5%;
|
||||
left: 8%;
|
||||
@@ -893,10 +893,6 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.navigator-dropdown.opened {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.navigator-option {
|
||||
display: block;
|
||||
border-left: 1px solid #232323;
|
||||
@@ -923,7 +919,7 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
}
|
||||
|
||||
.navigator-option.disabled {
|
||||
color: #AAAAAA; /* Gray color */
|
||||
color: #AAAAAA;
|
||||
}
|
||||
|
||||
.navigator-option:hover {
|
||||
@@ -1013,8 +1009,8 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
#file-system-browser-dialog {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
top: 65px;
|
||||
bottom: 50px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
display: none;
|
||||
z-index: 2;
|
||||
z-index: 999;
|
||||
padding: 5px 0;
|
||||
margin: 0px;
|
||||
font-family: 'Cabin', Sans-serif;
|
||||
@@ -185,6 +185,7 @@
|
||||
position: fixed;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
max-height: 22px;
|
||||
width: 100%;
|
||||
z-index: 900;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
border-right: 1px solid #000 !important;
|
||||
border-bottom: 1px solid #000 !important;
|
||||
box-shadow: 5px 5px 5px var(--shadow-color);
|
||||
animation: fadeIn 0.3s, fadeOut 0.3s 4.7s;
|
||||
animation: fadeIn 0.3s, fadeOut 0.3s 9.7s; /* animation for notifications fade out effect */
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-items: stretch;
|
||||
@@ -60,7 +60,7 @@
|
||||
flex-shrink: 0; /* prevent button from shrinking */
|
||||
}
|
||||
|
||||
.shine-effect {
|
||||
.notification-shine-effect {
|
||||
background: linear-gradient(to right, transparent, #fff, transparent);
|
||||
width: 100%;
|
||||
top: -1px;
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
--border-color-dark: #000000;
|
||||
--border-color-dialog: #1E90FF;
|
||||
--shadow-color: #000000;
|
||||
--highlight-color: #383838AA;
|
||||
--text-foreground: #6DCBFE;
|
||||
--light-row-background: #28292B;
|
||||
--dark-row-background: #191E21;
|
||||
}
|
||||
|
||||
html,
|
||||
@@ -45,13 +48,58 @@ body {
|
||||
background-color: #222;
|
||||
min-width: 100%;
|
||||
min-height: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
padding-top: 20px;
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
bottom: 50px;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
transition: bottom 1s ease, height 1s ease;
|
||||
}
|
||||
|
||||
#modal-background {
|
||||
main.audio-player-not-shown {
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
main.audio-player-full-height {
|
||||
bottom: calc(100% - 22px); /* full height minus menu height */
|
||||
}
|
||||
|
||||
.audio-player-container {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
transition: height 1s ease;
|
||||
}
|
||||
|
||||
.audio-player-container.not-shown {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
.audio-player-container.full-height {
|
||||
height: calc(100% - 22px); /* full height minus menu height */
|
||||
}
|
||||
|
||||
#modal-background-menu {
|
||||
display: none;
|
||||
z-index: 998;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
min-width: 100%;
|
||||
min-height: 22px;
|
||||
background-color: #000000;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
#modal-background-article {
|
||||
display: none;
|
||||
z-index: 998;
|
||||
position: absolute;
|
||||
@@ -101,6 +149,10 @@ main {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#audio-player-full-height-toggle, #audio-player-close {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.text-light-one {
|
||||
color: #6DCBFE;
|
||||
}
|
||||
@@ -134,6 +186,135 @@ main {
|
||||
.no-underline {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.form-row-align-start {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
flex: 2 0 27%;
|
||||
min-width: 200px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
flex: 0 0 70%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.form-field input[type="text"],
|
||||
.form-field input[type="number"],
|
||||
.form-field input[type="date"],
|
||||
.form-field input[type="datetime"],
|
||||
.form-field input[type="datetime-local"],
|
||||
.form-field textarea,
|
||||
.form-field input[type="password"] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-table {
|
||||
max-height: 150px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.form-table > div:nth-child(even) {
|
||||
background-color: var(--dark-row-background);
|
||||
}
|
||||
|
||||
.form-table > div:nth-child(odd) {
|
||||
background-color: var(--light-row-background);
|
||||
}
|
||||
|
||||
.form-description {
|
||||
margin-left: 25px;
|
||||
}
|
||||
/*
|
||||
.text-center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
*/
|
||||
.invalid-feedback {
|
||||
flex: 0 0 100%;
|
||||
}
|
||||
|
||||
.mandatory-field {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.engraved-title {
|
||||
margin: 0px;
|
||||
font-size: 3rem;
|
||||
background-color: var(--shadow-color);
|
||||
background-clip: text;
|
||||
-webkit-background-clip: text;
|
||||
color: transparent;
|
||||
text-shadow: var(--highlight-color) 2px 2px 2px;
|
||||
}
|
||||
|
||||
.engraved-panel {
|
||||
background-color: #00000033;
|
||||
border-radius: 5px;
|
||||
min-height: 70px;
|
||||
padding: 10px;
|
||||
-webkit-box-shadow: 0 0 7px 0px var(--shadow-color) inset;
|
||||
-moz-box-shadow: 0 0 7px 0px var(--shadow-color) inset;
|
||||
box-shadow: 0 0 7px 0px var(--shadow-color) inset;
|
||||
flex: 0 0 70%;
|
||||
}
|
||||
|
||||
.form-table-row {
|
||||
padding: 3px 8px;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
/*justify-content: space-between;*/
|
||||
border-top: 1px solid var(--border-color-light);
|
||||
border-left: 1px solid var(--border-color-light);
|
||||
border-bottom: 1px solid var(--border-color-dark);
|
||||
border-right: 1px solid var(--border-color-dark);
|
||||
}
|
||||
|
||||
.form-table-row span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.remove-form-table-row-icon {
|
||||
width: 15px;
|
||||
flex-shrink: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.add-form-table-row-icon {
|
||||
width: 15px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Margins */
|
||||
.mt-0 {
|
||||
margin-top: 0px;
|
||||
@@ -1244,5 +1425,4 @@ main {
|
||||
|
||||
/* For desktop: */
|
||||
@media only screen and (min-width: 768px) {
|
||||
|
||||
}
|
||||
@@ -52,5 +52,5 @@
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: none;
|
||||
resize: vertical;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg fill="#4AA747" width="800px" height="800px" viewBox="0 0 1920 1920" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m764.386 112.941 225.882 338.824H225.882v112.94H1920v1072.942c0 93.402-76.01 169.412-169.412 169.412H169.412C76.009 1807.059 0 1731.049 0 1637.647V112.941h764.386ZM1040 858.846H880v240H640v160h240v240h160v-240h240v-160h-240v-240Z" fill-rule="evenodd"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 501 B |
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg fill="#4AA747" width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5.755,20.283,4,8H20L18.245,20.283A2,2,0,0,1,16.265,22H7.735A2,2,0,0,1,5.755,20.283ZM21,4H16V3a1,1,0,0,0-1-1H9A1,1,0,0,0,8,3V4H3A1,1,0,0,0,3,6H21a1,1,0,0,0,0-2Z"/></svg>
|
||||
|
After Width: | Height: | Size: 402 B |
@@ -2,10 +2,13 @@
|
||||
//| DOM Elements |
|
||||
//+======================================================================================+
|
||||
|
||||
const modalBackground = document.getElementById('modal-background');
|
||||
const modalBackgroundMenu = document.getElementById('modal-background-menu');
|
||||
const modalBackgroundArticle = document.getElementById('modal-background-article');
|
||||
const fileSystemBrowserDialog = document.getElementById('file-system-browser-dialog');
|
||||
const fileSystemBrowserTreeview = document.getElementById('file-system-browser-treeview');
|
||||
const pathSegmentsContainer = document.getElementById('navigator-path-segments');
|
||||
const article = document.querySelector('article');
|
||||
const menubar = document.getElementsByClassName('menubar')[0];
|
||||
|
||||
const fileSystemTreeViewContainer = document.getElementById('file-system-browser-file-system-treeview-container');
|
||||
const fileSystemExplorerContainer = document.getElementById('file-system-browser-file-system-explorer-container');
|
||||
@@ -46,6 +49,7 @@ const btnExtraLargeIconsView = document.getElementById('navigator-extra-large-ic
|
||||
const btnFileSystemBrowserEditPath = document.getElementById('navigator-edit-path-button');
|
||||
const btnFileSystemBrowserSubmitPath = document.getElementById('navigator-navigate-button');
|
||||
const btnFileSystemBrowserConfirm = document.getElementById('file-system-browser-confirm-button');
|
||||
const btnFileSystemBrowserCancel = document.getElementById('file-system-browser-cancel-button');
|
||||
|
||||
const selectedFileSystemElementsInput = document.getElementById('file-system-browser-selected-element');
|
||||
|
||||
@@ -177,18 +181,17 @@ async function initFileSystemBrowser(serverBasePathValue, clientBasePathValue, i
|
||||
addHorizontalScrolling(addressBar);
|
||||
//switchViewMode('list', null, true);
|
||||
switchViewMode(viewModeValue, viewModeValue === 'list' ? null : iconSizeValue, true);
|
||||
|
||||
// TODO: to be removed:
|
||||
showFileSystemBrowserDialogAsync(initialPath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the file system browser dialog.
|
||||
*/
|
||||
async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue) {
|
||||
async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue, includeFilesValue, onConfirmCallback) {
|
||||
if (path !== undefined && path !== null) {
|
||||
showHiddenElements = showHiddenElementsValue;
|
||||
modalBackground.style.display = 'block';
|
||||
includeFiles = includeFilesValue;
|
||||
modalBackgroundMenu.style.display = 'block';
|
||||
modalBackgroundArticle.style.display = 'block';
|
||||
fileSystemBrowserDialog.style.display = 'block';
|
||||
if (!path.endsWith(pathSeparator))
|
||||
path += pathSeparator;
|
||||
@@ -197,6 +200,15 @@ async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue) {
|
||||
await toggleFileSystemTreeViewAsync(false);
|
||||
await toggleShowFileSystemElementsThumbnailsAsync(false);
|
||||
await navigateToPathAsync(path, false, false);
|
||||
// add click handler for confirm button
|
||||
btnFileSystemBrowserConfirm.onclick = function () {
|
||||
const selectedPaths = selectedFileSystemElementsInput.value;
|
||||
if (onConfirmCallback && typeof onConfirmCallback === 'function')
|
||||
onConfirmCallback(selectedPaths);
|
||||
// hide dialog
|
||||
hideFileSystemBrowserDialog();
|
||||
};
|
||||
btnFileSystemBrowserCancel.onclick = hideFileSystemBrowserDialog;
|
||||
} else
|
||||
notificationService.Show("Path cannot be null!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
|
||||
}
|
||||
@@ -205,8 +217,9 @@ async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue) {
|
||||
* Hides the file system browser dialog.
|
||||
*/
|
||||
function hideFileSystemBrowserDialog() {
|
||||
modalBackground.style.display = 'block';
|
||||
fileSystemBrowserDialog.style.display = 'block';
|
||||
modalBackgroundMenu.style.display = 'none';
|
||||
modalBackgroundArticle.style.display = 'none';
|
||||
fileSystemBrowserDialog.style.display = 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,7 +449,7 @@ async function handlePathSegmentComboboxChangeAsync(e) {
|
||||
|
||||
// fetch directory data for the path
|
||||
try {
|
||||
await streamFileSystemDirectoriesAsync(pathValue, (parsedItem) => {
|
||||
await fetchFileSystemDirectoriesAsync(pathValue, (parsedItem) => {
|
||||
addDirectoryOption(dropdown, pathValue, parsedItem.name, async () => {
|
||||
const newPath = pathValue + (!pathValue.endsWith(pathSeparator) ? pathSeparator : '') + parsedItem.name + pathSeparator;
|
||||
addressBarInput.value = newPath;
|
||||
@@ -678,8 +691,8 @@ async function loadFileSystemTreeViewChildNodesAsync(parentNode, path) {
|
||||
childNodes.innerHTML = '';
|
||||
try {
|
||||
showBusyIndicator();
|
||||
// stream directory information and create nodes for each
|
||||
await streamFileSystemDirectoriesAsync(path, (dir) => {
|
||||
// fetch directory information and create nodes for each
|
||||
await fetchFileSystemDirectoriesAsync(path, (dir) => {
|
||||
dir.itemType = 'Directory';
|
||||
const dirNode = createFileSystemTreeViewTreeNode(dir);
|
||||
childNodes.appendChild(dirNode);
|
||||
@@ -693,85 +706,41 @@ async function loadFileSystemTreeViewChildNodesAsync(parentNode, path) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams directory information from the server for a given path.
|
||||
* Fetches directory information from the server for a given path.
|
||||
* @param {string} path - The path to get directories from.
|
||||
* @param {Function} callback - Function to call for each directory received.
|
||||
*/
|
||||
async function streamFileSystemDirectoriesAsync(path, callback) {
|
||||
await streamJsonDataAsync(`${clientBasePath}directories/get-directories?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`, callback, 'Directory');
|
||||
async function fetchFileSystemDirectoriesAsync(path, callback) {
|
||||
await fetchJsonDataAsync(`${clientBasePath}directories/get-directories?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`, callback, 'Directory');
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams file information from the server for a given path.
|
||||
* Fetches file information from the server for a given path.
|
||||
* @param {string} path - The path to get files from.
|
||||
* @param {Function} callback - Function to call for each file received.
|
||||
*/
|
||||
async function streamFileSystemFilesAsync(path, callback) {
|
||||
await streamJsonDataAsync(`${clientBasePath}files/get-tree-files?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`, callback, 'File');
|
||||
async function fetchFileSystemFilesAsync(path, callback) {
|
||||
await fetchJsonDataAsync(`${clientBasePath}files/get-tree-files?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`, callback, 'File');
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams JSON data from a given URL and processes it item by item.
|
||||
* This function handles potentially large datasets by processing the data as it arrives,
|
||||
* rather than waiting for the entire response to load.
|
||||
* Fetches and processes JSON data from a given URL.
|
||||
* This function handles the data by processing all items in the response.data array
|
||||
* and passing them through the callback function.
|
||||
*
|
||||
* @param {string} url - The URL to fetch JSON data from.
|
||||
* @param {Function} callback - Function to call for each processed item.
|
||||
* @param {string} itemType - Type of item being processed ('File' or 'Directory').
|
||||
*/
|
||||
async function streamJsonDataAsync(url, callback, itemType) {
|
||||
// initiate the fetch request from the API
|
||||
const response = await fetch(url);
|
||||
// get a reader for the response body stream
|
||||
const reader = response.body.getReader();
|
||||
// create a decoder to convert the incoming byte stream to text
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = ''; // buffer to hold incoming data that hasn't been fully processed yet
|
||||
// function to process the buffer and extract complete JSON objects
|
||||
function processBuffer() {
|
||||
let startIndex = 0;
|
||||
let endIndex;
|
||||
// look for complete JSON objects (ending with '},')
|
||||
while ((endIndex = buffer.indexOf('},', startIndex)) !== -1) {
|
||||
// extract a single JSON object
|
||||
let itemJson = buffer.substring(startIndex, endIndex + 1);
|
||||
// remove leading comma if present (from array structure)
|
||||
if (itemJson.startsWith(',')) itemJson = itemJson.substring(1);
|
||||
// remove surrounding square brackets (array indicators)
|
||||
itemJson = itemJson.replace(/^\[|\]$/g, '');
|
||||
// parse the JSON string into an object
|
||||
var item = JSON.parse(itemJson);
|
||||
// manually specify he type of to the parsed object
|
||||
async function fetchJsonDataAsync(url, callback, itemType) {
|
||||
const response = await callApiGetAsync(url);
|
||||
if (response !== undefined) {
|
||||
// process each item in the response.data array
|
||||
for (let item of response) {
|
||||
// manually specify the type to the parsed object
|
||||
item.itemType = itemType;
|
||||
// call the provided callback function with the processed item
|
||||
callback(item);
|
||||
// move the start index to the beginning of the next item
|
||||
startIndex = endIndex + 2;
|
||||
}
|
||||
// keep any incomplete JSON data in the buffer for the next processing cycle
|
||||
buffer = buffer.slice(startIndex);
|
||||
}
|
||||
// main loop to read the stream
|
||||
while (true) {
|
||||
// read a chunk from the stream
|
||||
const { done, value } = await reader.read();
|
||||
// if the stream is finished, break the loop
|
||||
if (done)
|
||||
break;
|
||||
// decode the chunk and add it to the buffer
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
// process the updated buffer
|
||||
processBuffer();
|
||||
}
|
||||
// process any remaining data in the buffer after the stream is complete
|
||||
if (buffer.trim()) {
|
||||
let finalJson = buffer.trim();
|
||||
if (finalJson.startsWith(',')) finalJson = finalJson.substring(1);
|
||||
finalJson = finalJson.replace(/^\[|\]$/g, '');
|
||||
if (finalJson !== '') {
|
||||
var item = JSON.parse(finalJson);
|
||||
item.itemType = itemType;
|
||||
callback(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -844,8 +813,8 @@ async function getFileSystemItemsAsync(path) {
|
||||
|
||||
try {
|
||||
showBusyIndicator();
|
||||
// stream file system items and create explorer items for each
|
||||
await streamFileSystemItemsAsync(path, (item) => {
|
||||
// fetch file system items and create explorer items for each
|
||||
await fetchFileSystemItemsAsync(path, (item) => {
|
||||
const newItem = createFileSystemExplorerItem(item);
|
||||
fileSystemExplorer.appendChild(newItem);
|
||||
});
|
||||
@@ -858,13 +827,14 @@ async function getFileSystemItemsAsync(path) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Streams both directories and files from a specified path.
|
||||
* @param {string} path - The file system path to stream items from.
|
||||
* Fetches both directories and files from a specified path.
|
||||
* @param {string} path - The file system path to fetch items from.
|
||||
* @param {Function} callback - Function to call for each item (directory or file) received.
|
||||
*/
|
||||
async function streamFileSystemItemsAsync(path, callback) {
|
||||
await streamFileSystemDirectoriesAsync(path, callback);
|
||||
await streamFileSystemFilesAsync(path, callback);
|
||||
async function fetchFileSystemItemsAsync(path, callback) {
|
||||
await fetchFileSystemDirectoriesAsync(path, callback);
|
||||
if (includeFiles)
|
||||
await fetchFileSystemFilesAsync(path, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1112,16 +1082,16 @@ function startSelection(e) {
|
||||
document.body.style.overflowY = 'hidden'; // needed in order to not put a vertical scrollbar on the document, while in vertical layout selection
|
||||
document.documentElement.style.overflowY = 'hidden';
|
||||
selectionStartPosition.x = e.pageX + fileSystemExplorer.scrollLeft;
|
||||
selectionStartPosition.y = e.pageY + fileSystemExplorerContainer.scrollTop; // not a mistake - in vertical mode, this is the overflow container!
|
||||
selectionStartPosition.y = (e.pageY - parseInt(window.getComputedStyle(menubar).height)) + fileSystemExplorerContainer.scrollTop; // not a mistake - in vertical mode, this is the overflow container!
|
||||
// place the selection rectangle at the clicked location (relative to the whole page, and taking into account scroll offset), with 0 size
|
||||
visibleSelectionRectangle.style.left = e.pageX + 'px';
|
||||
visibleSelectionRectangle.style.top = e.pageY + 'px';
|
||||
visibleSelectionRectangle.style.top = (e.pageY - parseInt(window.getComputedStyle(menubar).height)) + 'px';
|
||||
visibleSelectionRectangle.style.width = '0px';
|
||||
visibleSelectionRectangle.style.height = '0px';
|
||||
visibleSelectionRectangle.style.visibility = 'visible';
|
||||
|
||||
selectionRectangle.style.left = e.pageX + 'px';
|
||||
selectionRectangle.style.top = e.pageY + 'px';
|
||||
selectionRectangle.style.top = (e.pageY - parseInt(window.getComputedStyle(menubar).height)) + 'px';
|
||||
selectionRectangle.style.width = '0px';
|
||||
selectionRectangle.style.height = '0px';
|
||||
}
|
||||
@@ -1134,7 +1104,7 @@ function updateSelection(e) {
|
||||
if (!isSelecting)
|
||||
return;
|
||||
currentMousePosition.x = e.pageX;
|
||||
currentMousePosition.y = e.pageY;
|
||||
currentMousePosition.y = e.pageY - parseInt(window.getComputedStyle(menubar).height);
|
||||
handleSelection();
|
||||
}
|
||||
|
||||
@@ -1225,10 +1195,10 @@ function handleSelection() {
|
||||
if (right > containerRect.right)
|
||||
visibleSelectionRectangle.style.width = (containerRect.right - left) + 'px';
|
||||
|
||||
if (top < containerRect.top) {
|
||||
const difference = containerRect.top - top;
|
||||
if (top < containerRect.top - parseInt(window.getComputedStyle(menubar).height)) {
|
||||
const difference = containerRect.top - top - parseInt(window.getComputedStyle(menubar).height);
|
||||
visibleSelectionRectangle.style.height = (parseFloat(visibleSelectionRectangle.style.height) - difference) + 'px';
|
||||
visibleSelectionRectangle.style.top = containerRect.top + 'px';
|
||||
visibleSelectionRectangle.style.top = (containerRect.top - parseInt(window.getComputedStyle(menubar).height)) + 'px';
|
||||
}
|
||||
if (bottom > containerRect.bottom)
|
||||
visibleSelectionRectangle.style.height = (containerRect.bottom - top) + 'px';
|
||||
@@ -1509,18 +1479,6 @@ async function toggleShowFileSystemElementsThumbnailsAsync(isManualSet) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes all comboboxes except for the one passed as an argument.
|
||||
* @param {HTMLElement} exceptionCheckbox - The checkbox of the combobox that should remain open.
|
||||
*/
|
||||
function closeAllComboboxesExcept(exceptionCheckbox) {
|
||||
const checkedCheckboxes = document.querySelectorAll('.enlightenment-toggle-checkbox:checked, .navigator-toggle-checkbox:checked');
|
||||
checkedCheckboxes.forEach(function (checkbox) {
|
||||
if (!exceptionCheckbox || checkbox.id !== exceptionCheckbox.id)
|
||||
checkbox.checked = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon of the node, based on it type.
|
||||
* @param {any} node The node for which to get the icon.
|
||||
@@ -1618,79 +1576,6 @@ addressBar.addEventListener('click', function (e) {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Detects changes on any combobox checkbox. If a combobox is opened, this will ensure all other comboboxes are closed.
|
||||
*/
|
||||
document.addEventListener('change', function (e) {
|
||||
if (e.target.matches('.enlightenment-toggle-checkbox, .navigator-toggle-checkbox'))
|
||||
if (e.target.checked)
|
||||
closeAllComboboxesExcept(e.target);
|
||||
});
|
||||
|
||||
/**
|
||||
* Event handler for when an option in the combobox is clicked.
|
||||
* This updates the displayed value of the combobox to the clicked option and closes the dropdown.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.matches('.enlightenment-option')) {
|
||||
var text = e.target.textContent;
|
||||
var combobox = e.target.closest('.enlightenment-combobox');
|
||||
|
||||
var selectedText = combobox.querySelector('.enlightenment-selected-text');
|
||||
if (selectedText)
|
||||
selectedText.textContent = text;
|
||||
|
||||
var toggleCheckbox = combobox.querySelector('.enlightenment-toggle-checkbox');
|
||||
if (toggleCheckbox)
|
||||
toggleCheckbox.checked = false;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Global click event for the entire document. Closes all combobox dropdowns if the clicked target is outside any combobox.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
// enlightenment combobox logic
|
||||
if (!e.target.closest('.enlightenment-combobox')) {
|
||||
const checkbox = document.querySelector('.enlightenment-toggle-checkbox:checked');
|
||||
if (checkbox)
|
||||
checkbox.checked = false;
|
||||
}
|
||||
// navigator combobox logic
|
||||
if (!e.target.closest('.navigator-combobox') && addressBar) {
|
||||
const checkbox = document.querySelector('.navigator-toggle-checkbox:checked');
|
||||
if (checkbox)
|
||||
checkbox.checked = false;
|
||||
// when drop down closes, hide address bar overflow
|
||||
addressBar.style.overflowX = 'auto';
|
||||
addressBar.style.overflowY = 'hidden';
|
||||
reattachDropdown();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Event handler for navigation combobox drop down item clicks.
|
||||
*/
|
||||
document.addEventListener("click", function (e) {
|
||||
if (e.target.matches('.navigator-option')) {
|
||||
// the address bar drop downs may be destroyed when an option is clicked - they are regenerated each time anyway
|
||||
addressBar.removeEventListener('scroll', adjustDropdownPosition);
|
||||
|
||||
var parentElement = e.target.parentElement;
|
||||
if (parentElement)
|
||||
parentElement.remove();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Prevents the global document click event from propagating when clicking on a combobox.
|
||||
* This ensures the dropdown doesn't close unintentionally.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.closest('.enlightenment-combobox, .navigator-combobox'))
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
/**
|
||||
* Handles the window resize event.
|
||||
*/
|
||||
|
||||
@@ -62,8 +62,8 @@ class NotificationService {
|
||||
else
|
||||
console.log(message);
|
||||
|
||||
// set a timeout to remove the notification after 5 seconds
|
||||
setTimeout(() => this.removeNotification(notification.id), 5000);
|
||||
// set a timeout to remove the notification after 10 seconds (fading out effect is handled in notification.css)
|
||||
setTimeout(() => this.removeNotification(notification.id), 10000);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,9 +75,8 @@ class NotificationService {
|
||||
if (index !== -1) {
|
||||
this.notifications.splice(index, 1);
|
||||
const element = document.getElementById(`notification-${id}`);
|
||||
if (element) {
|
||||
if (element)
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ class NotificationService {
|
||||
notificationElement.id = `notification-${notification.id}`;
|
||||
notificationElement.className = `notification ${notification.type}`;
|
||||
notificationElement.innerHTML = `
|
||||
<div class="shine-effect"></div>
|
||||
<div class="notification-shine-effect"></div>
|
||||
<div class="notification-body">
|
||||
<span class="notification-message">${notification.message}</span>
|
||||
<button class="close-button" onclick="notificationService.removeNotification('${notification.id}')">×</button>
|
||||
|
||||
@@ -4,8 +4,8 @@ const progressIndicator = document.getElementById('progress-indicator');
|
||||
const progressIndicatorValue = document.getElementById('progress-indicator-value');
|
||||
const progressIndicatorValueShadow = document.getElementById('progress-indicator-value-shadow');
|
||||
const progressIndicatorValueText = document.getElementById('progress-indicator-value-text');
|
||||
|
||||
|
||||
const audioPlayerFullHeightToggle = document.getElementById('audio-player-full-height-toggle');
|
||||
const audioPlayerClose = document.getElementById('audio-player-close');
|
||||
|
||||
let enableConsoleDebugMessages = false; // whether to display debug messages at the developer console, or not
|
||||
|
||||
@@ -25,6 +25,8 @@ async function callApiGetAsync(url) {
|
||||
try {
|
||||
// create the URL for the API endpoint
|
||||
const response = await fetch(url); // call the API
|
||||
if (response.redirected) // if a redirect is requested, perform it
|
||||
window.location.href = response.url;
|
||||
if (!response.ok)
|
||||
throw new Error('Network response was not ok');
|
||||
const jsonResponse = await response.json();
|
||||
@@ -38,6 +40,157 @@ async function callApiGetAsync(url) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a POST request to the specified API endpoint.
|
||||
* @param {string} url - The API endpoint URL.
|
||||
* @param {Object} data - The data to send in the request body.
|
||||
* @param {Object} [options] - Additional options for the request.
|
||||
* @param {boolean} [options.useAntiForgery=true] - Whether to include anti-forgery token.
|
||||
* @param {Object} [options.headers] - Additional headers to include.
|
||||
* @returns {Promise<any>} The response data if successful, undefined otherwise.
|
||||
*/
|
||||
async function callApiPostAsync(url, data, options = {}) {
|
||||
const defaultOptions = {
|
||||
useAntiForgery: true,
|
||||
headers: {}
|
||||
};
|
||||
const finalOptions = { ...defaultOptions, ...options };
|
||||
try {
|
||||
// prepare headers
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
...finalOptions.headers
|
||||
};
|
||||
// add anti-forgery token if enabled
|
||||
if (finalOptions.useAntiForgery) {
|
||||
const token = document.querySelector('input[name="__RequestVerificationToken"]')?.value;
|
||||
if (token)
|
||||
headers['RequestVerificationToken'] = token;
|
||||
}
|
||||
// make the request
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (response.redirected) // if a redirect is requested, perform it
|
||||
window.location.href = response.url;
|
||||
if (!response.ok)
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
const jsonResponse = await response.json();
|
||||
if (jsonResponse.success) {
|
||||
if (jsonResponse.message)
|
||||
notificationService.show(jsonResponse.message, NotificationType.SUCCESS);
|
||||
return jsonResponse.data;
|
||||
}
|
||||
else
|
||||
notificationService.show(jsonResponse.errorMessage, NotificationType.ERROR);
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
notificationService.show(error, NotificationType.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
//+======================================================================================+
|
||||
//| Website navigation |
|
||||
//+======================================================================================+
|
||||
|
||||
/**
|
||||
* Initializes navigation by setting the initial history state, intercepting link clicks,
|
||||
* and managing back/forward browser actions.
|
||||
*/
|
||||
function initializeNavigation() {
|
||||
// store initial state
|
||||
const initialState = {
|
||||
url: window.location.href,
|
||||
content: document.querySelector('main').innerHTML,
|
||||
title: document.title
|
||||
};
|
||||
history.replaceState(initialState, document.title, window.location.href);
|
||||
// initial nav-link binding
|
||||
bindNavigationLinks();
|
||||
|
||||
// handle browser back/forward
|
||||
window.addEventListener('popstate', handlePopState);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds AJAX navigation behavior to links marked with .nav-link class.
|
||||
*/
|
||||
function bindNavigationLinks() {
|
||||
document.querySelectorAll('.nav-link').forEach(link => {
|
||||
// only bind if not already bound
|
||||
if (!link.dataset.boundNavigation) {
|
||||
link.addEventListener('click', handleNavigation);
|
||||
link.dataset.boundNavigation = 'true';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles link clicks to navigate dynamically without reloading the page.
|
||||
* @param {Event} e - The click event for a navigation link.
|
||||
*/
|
||||
async function handleNavigation(e) {
|
||||
e.preventDefault();
|
||||
const url = e.target.href;
|
||||
await updateContent(url, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores page content and title when navigating with browser back/forward buttons.
|
||||
* @param {PopStateEvent} e - The popstate event with previous state data.
|
||||
*/
|
||||
async function handlePopState(e) {
|
||||
if (e.state) {
|
||||
// if we have cached content in state, use it immediately
|
||||
if (e.state.content) {
|
||||
document.querySelector('main').innerHTML = e.state.content;
|
||||
document.title = e.state.title;
|
||||
}
|
||||
// still fetch fresh content to ensure it's up to date
|
||||
await updateContent(e.state.url, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads new page content and updates the URL and history if required.
|
||||
* @param {string} url - URL to fetch new content from.
|
||||
* @param {boolean} addToHistory - Whether to add the new state to history.
|
||||
*/
|
||||
async function updateContent(url, addToHistory) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const html = await response.text();
|
||||
|
||||
// parse the new content
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
const content = doc.querySelector('main').innerHTML;
|
||||
const title = doc.querySelector('title')?.textContent || document.title;
|
||||
|
||||
// update the page
|
||||
document.querySelector('main').innerHTML = content;
|
||||
document.title = title;
|
||||
|
||||
// bind navigation links in the new content
|
||||
bindNavigationLinks();
|
||||
|
||||
// save to history if needed
|
||||
if (addToHistory) {
|
||||
const state = {
|
||||
url: url,
|
||||
content: content,
|
||||
title: title
|
||||
};
|
||||
history.pushState(state, title, url);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Navigation failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
//+======================================================================================+
|
||||
//| Common Helper Functions |
|
||||
//+======================================================================================+
|
||||
@@ -47,7 +200,7 @@ async function callApiGetAsync(url) {
|
||||
*/
|
||||
function showBusyIndicator() {
|
||||
//if (ajaxCallCounter === 0)
|
||||
//progressIndicator.classList.remove('hidden');
|
||||
//progressIndicator.classList.remove('hidden');
|
||||
ajaxCallCounter++;
|
||||
}
|
||||
|
||||
@@ -57,7 +210,7 @@ function showBusyIndicator() {
|
||||
function hideBusyIndicator() {
|
||||
ajaxCallCounter--;
|
||||
//if (ajaxCallCounter === 0)
|
||||
//progressIndicator.classList.add('hidden');
|
||||
//progressIndicator.classList.add('hidden');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,11 +345,11 @@ const scrollHandler = function (event) {
|
||||
*/
|
||||
function addHorizontalScrolling(idOrElement) {
|
||||
let element = idOrElement;
|
||||
if (typeof idOrElement === 'string')
|
||||
if (typeof idOrElement === 'string')
|
||||
element = document.getElementById(idOrElement);
|
||||
if (element instanceof HTMLElement)
|
||||
if (element instanceof HTMLElement)
|
||||
element.addEventListener('wheel', scrollHandler, { passive: false });
|
||||
else
|
||||
else
|
||||
console.error('Invalid input: Expected an element ID or HTMLElement');
|
||||
}
|
||||
|
||||
@@ -206,11 +359,11 @@ function addHorizontalScrolling(idOrElement) {
|
||||
*/
|
||||
function removeHorizontalScrolling(idOrElement) {
|
||||
let element = idOrElement;
|
||||
if (typeof idOrElement === 'string')
|
||||
if (typeof idOrElement === 'string')
|
||||
element = document.getElementById(idOrElement);
|
||||
if (element instanceof HTMLElement)
|
||||
if (element instanceof HTMLElement)
|
||||
element.removeEventListener('wheel', scrollHandler, { passive: false });
|
||||
else
|
||||
else
|
||||
console.error('Invalid input: Expected an element ID or HTMLElement');
|
||||
}
|
||||
|
||||
@@ -237,3 +390,122 @@ function getElementOffset(id) {
|
||||
height: 0
|
||||
};
|
||||
}
|
||||
|
||||
document.querySelectorAll('.remove-form-table-row-icon').forEach(icon => {
|
||||
icon.addEventListener('click', function () {
|
||||
this.parentElement.remove();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggles the visibility of the audio player.
|
||||
*/
|
||||
function toggleAudioPlayerVisibility() {
|
||||
const playerContainer = document.querySelector('.audio-player-container');
|
||||
const contentContainer = document.querySelector('main');
|
||||
playerContainer.classList.toggle('not-shown');
|
||||
contentContainer.classList.toggle('audio-player-not-shown');
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the display of the audio player as collapsed player, or full height player.
|
||||
*/
|
||||
function toggleAudioPlayerFullHeight() {
|
||||
const playerContainer = document.querySelector('.audio-player-container');
|
||||
const contentContainer = document.querySelector('main');
|
||||
playerContainer.classList.toggle('full-height');
|
||||
contentContainer.classList.toggle('audio-player-full-height');
|
||||
}
|
||||
|
||||
if (audioPlayerFullHeightToggle)
|
||||
audioPlayerFullHeightToggle.addEventListener('click', toggleAudioPlayerFullHeight);
|
||||
if (audioPlayerClose)
|
||||
audioPlayerClose.addEventListener('click', toggleAudioPlayerVisibility);
|
||||
|
||||
|
||||
/**
|
||||
* Closes all comboboxes except for the one passed as an argument.
|
||||
* @param {HTMLElement} exceptionCheckbox - The checkbox of the combobox that should remain open.
|
||||
*/
|
||||
function closeAllComboboxesExcept(exceptionCheckbox) {
|
||||
const checkedCheckboxes = document.querySelectorAll('.enlightenment-toggle-checkbox:checked, .navigator-toggle-checkbox:checked');
|
||||
checkedCheckboxes.forEach(function (checkbox) {
|
||||
if (!exceptionCheckbox || checkbox.id !== exceptionCheckbox.id)
|
||||
checkbox.checked = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects changes on any combobox checkbox. If a combobox is opened, this will ensure all other comboboxes are closed.
|
||||
*/
|
||||
document.addEventListener('change', function (e) {
|
||||
if (e.target.matches('.enlightenment-toggle-checkbox, .navigator-toggle-checkbox'))
|
||||
if (e.target.checked)
|
||||
closeAllComboboxesExcept(e.target);
|
||||
});
|
||||
|
||||
/**
|
||||
* Event handler for when an option in the combobox is clicked.
|
||||
* This updates the displayed value of the combobox to the clicked option and closes the dropdown.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.matches('.enlightenment-option')) {
|
||||
var text = e.target.textContent;
|
||||
var combobox = e.target.closest('.enlightenment-combobox');
|
||||
|
||||
var selectedText = combobox.querySelector('.enlightenment-selected-text');
|
||||
if (selectedText)
|
||||
selectedText.textContent = text;
|
||||
|
||||
var toggleCheckbox = combobox.querySelector('.enlightenment-toggle-checkbox');
|
||||
if (toggleCheckbox)
|
||||
toggleCheckbox.checked = false;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Global click event for the entire document. Closes all combobox dropdowns if the clicked target is outside any combobox.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
// enlightenment combobox logic
|
||||
if (!e.target.closest('.enlightenment-combobox')) {
|
||||
const checkbox = document.querySelector('.enlightenment-toggle-checkbox:checked');
|
||||
if (checkbox)
|
||||
checkbox.checked = false;
|
||||
}
|
||||
// navigator combobox logic
|
||||
if (!e.target.closest('.navigator-combobox') && typeof addressBar !== 'undefined' && addressBar !== null) {
|
||||
const checkbox = document.querySelector('.navigator-toggle-checkbox:checked');
|
||||
if (checkbox)
|
||||
checkbox.checked = false;
|
||||
// when drop down closes, hide address bar overflow
|
||||
addressBar.style.overflowX = 'auto';
|
||||
addressBar.style.overflowY = 'hidden';
|
||||
reattachDropdown();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Event handler for navigation combobox drop down item clicks.
|
||||
*/
|
||||
document.addEventListener("click", function (e) {
|
||||
if (e.target.matches('.navigator-option')) {
|
||||
// the address bar drop downs may be destroyed when an option is clicked - they are regenerated each time anyway
|
||||
addressBar.removeEventListener('scroll', adjustDropdownPosition);
|
||||
|
||||
var parentElement = e.target.parentElement;
|
||||
if (parentElement)
|
||||
parentElement.remove();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Prevents the global document click event from propagating when clicking on a combobox.
|
||||
* This ensures the dropdown doesn't close unintentionally.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.closest('.enlightenment-combobox, .navigator-combobox'))
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initializeNavigation);
|
||||
Reference in new issue
Block a user