mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Implements authentication system
This commit is contained in:
1 parent
38829d64ff
commit
a6dcf65d1c
103 files changed
+2983
-454
No files matched your search
@@ -3,6 +3,7 @@ using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Common.Models.Common;
|
||||
using Lumina.Presentation.Web.Common.Models.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,16 +26,19 @@ namespace Lumina.Presentation.Web.Common.Api;
|
||||
public class ApiHttpClient : IApiHttpClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly HttpContext? _httpContext;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiHttpClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">Injected HttpClient for interacting with the API.</param>
|
||||
/// <param name="httpContextAccessor">Injected service for providing the current HTTP context.</param>
|
||||
/// <param name="serverConfigurationOptions">Injected server configuration application settings.</param>
|
||||
public ApiHttpClient(HttpClient httpClient, IOptionsSnapshot<ServerConfigurationModel> serverConfigurationOptions)
|
||||
public ApiHttpClient(HttpClient httpClient, IHttpContextAccessor httpContextAccessor, IOptionsSnapshot<ServerConfigurationModel> serverConfigurationOptions)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_httpContext = httpContextAccessor.HttpContext;
|
||||
// read the API server configuration values from the configuration, and assign them to the injected client
|
||||
ServerConfigurationModel serverConfigurationModel = serverConfigurationOptions.Value;
|
||||
httpClient.BaseAddress = new Uri($"{serverConfigurationModel.BaseAddress}:{serverConfigurationModel.Port}/api/v{serverConfigurationModel.ApiVersion}/");
|
||||
@@ -52,14 +56,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
public async Task<TResponse> GetAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> GetAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -68,14 +72,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, string? token = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
// send the request and expect only headers initially - this prevents the client from buffering the entire response
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
@@ -93,14 +97,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A model containing the deserialized blob.</returns>
|
||||
public async Task<BlobDataModel> GetBlobAsync(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<BlobDataModel> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -125,14 +129,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the DELETE request.</returns>
|
||||
public async Task<TResponse> DeleteAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> DeleteAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Delete, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -143,14 +147,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and send to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
public async Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Put, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -162,14 +166,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
public async Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Post, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -203,4 +207,16 @@ public class ApiHttpClient : IApiHttpClient
|
||||
throw new ApiException(problemDetails, response.StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the authentication header for the current user, if available.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="AuthenticationHeaderValue"/> with a Bearer token if the user's token is found, <see langword="null"/> otherwise.
|
||||
/// </returns>
|
||||
private AuthenticationHeaderValue? GetAuthenticationHeader()
|
||||
{
|
||||
string? token = _httpContext?.User?.FindFirst("Token")?.Value;
|
||||
return !string.IsNullOrEmpty(token) ? new AuthenticationHeaderValue("Bearer", token) : null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Models.FileSystemManagement;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -17,39 +17,35 @@ public interface IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
Task<TResponse> GetAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> GetAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result as a streamable response.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A model containing the deserialized blob.</returns>
|
||||
Task<BlobDataModel> GetBlobAsync(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<BlobDataModel> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a DELETE request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the DELETE request.</returns>
|
||||
Task<TResponse> DeleteAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> DeleteAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
@@ -58,10 +54,9 @@ public interface IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and send to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
@@ -70,8 +65,7 @@ public interface IApiHttpClient
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="token">The token used for authentication with the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="InitializationRequirement"/> to ensure that the application is initialized before allowing authorization.
|
||||
/// </summary>
|
||||
public class InitializationHandler : AuthorizationHandler<InitializationRequirement>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializationHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected HTTP typed client for interactions with the API.</param>
|
||||
/// <param name="cache">Cache for storing the initialization status.</param>
|
||||
public InitializationHandler(IApiHttpClient apiHttpClient, IMemoryCache cache)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the application initialization status and authorizes the requirement if initialized.
|
||||
/// </summary>
|
||||
/// <param name="context">The authorization context.</param>
|
||||
/// <param name="requirement">The initialization requirement to be evaluated.</param>
|
||||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, InitializationRequirement requirement)
|
||||
{
|
||||
InitializationModel result = await _apiHttpClient.GetAsync<InitializationModel>("initialization/");
|
||||
HttpContext? httpContext = context.Resource as HttpContext;
|
||||
if (result.IsInitialized)
|
||||
{
|
||||
// admin account was registered, remove this requirement from the session
|
||||
httpContext?.Session.Remove(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP);
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
else // store in session that super admin setup is needed
|
||||
httpContext?.Session.SetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP, "true");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a requirement for initialization status in the authorization process.
|
||||
/// </summary>
|
||||
public class InitializationRequirement : IAuthorizationRequirement
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the timeout duration, in minutes, for caching the initialization check.
|
||||
/// </summary>
|
||||
public int CacheTimeoutMinutes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializationRequirement"/> class.
|
||||
/// </summary>
|
||||
/// <param name="cacheTimeoutMinutes">The cache timeout in minutes for the initialization status.</param>
|
||||
public InitializationRequirement(int cacheTimeoutMinutes = 5)
|
||||
{
|
||||
CacheTimeoutMinutes = cacheTimeoutMinutes;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class ApiExceptionFilter : IExceptionFilter
|
||||
if (context.Exception is ApiException apiException)
|
||||
{
|
||||
// handle unauthorized errors by prompting the user to re-login
|
||||
if (apiException.HttpStatusCode == HttpStatusCode.Unauthorized)
|
||||
if (apiException.HttpStatusCode == HttpStatusCode.Unauthorized) // HTTP 401 Unauthorized actually means lack of valid authentication credentials (not logged in)
|
||||
{
|
||||
SignOutSynchronously(context.HttpContext);
|
||||
string currentUrl = context.HttpContext.Request.GetDisplayUrl();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Filters;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute that enforces application initialization checks on controller actions.
|
||||
/// </summary>
|
||||
public class InitializationCheckAttribute : ActionFilterAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Asynchronously executes the initialization check before the action executes.
|
||||
/// </summary>
|
||||
/// <param name="context">The context for the action being executed.</param>
|
||||
/// <param name="next">Delegate to execute the next action filter in the pipeline.</param>
|
||||
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
IAuthorizationService authorizationService = context.HttpContext.RequestServices.GetRequiredService<IAuthorizationService>();
|
||||
await authorizationService.AuthorizeAsync(context.HttpContext.User, context.HttpContext, "RequireInitialization");
|
||||
await next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Lumina.Presentation.Web.Common.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Constants shared by HttpContext across a HTTP request (avoid magic strings).
|
||||
/// </summary>
|
||||
public static class HttpContextItemKeys
|
||||
{
|
||||
public const string ERRORS = "errors";
|
||||
public const string PENDING_SUPER_ADMIN_SETUP = "PendingSuperAdminSetup";
|
||||
}
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.MediaContributors;
|
||||
@@ -20,4 +19,4 @@ public class MediaContributorModel
|
||||
/// Gets the role of the contributor.
|
||||
/// </summary>
|
||||
public MediaContributorRoleModel? Role { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an item in a combobox.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The type used for the <see cref="Value"/> property of the item.</typeparam>
|
||||
[DebuggerDisplay("{Text}")]
|
||||
public class ComboboxItem<TValue>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the text of the item, that is visible to the user.
|
||||
/// </summary>
|
||||
public string? Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the item, that is used by the application.
|
||||
/// </summary>
|
||||
public TValue? Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the property indicating whether this element can be selected or not.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the request model for account password change.
|
||||
/// </summary>
|
||||
/// <param name="Username">The username of the account.</param>
|
||||
/// <param name="CurrentPassword">The current password of the account.</param>
|
||||
/// <param name="NewPassword">The new password of the account.</param>
|
||||
/// <param name="NewPasswordConfirm">The confirmation of the new password of the account.</param>
|
||||
public record ChangePasswordRequestModel(
|
||||
string? Username,
|
||||
string? CurrentPassword,
|
||||
string? NewPassword,
|
||||
string? NewPasswordConfirm
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response model for an account password change request.
|
||||
/// </summary>
|
||||
/// <param name="IsPasswordChanged">Whether the password was changed or not.</param>
|
||||
[DebuggerDisplay("IsPasswordChanged: {IsPasswordChanged}")]
|
||||
public record ChangePasswordResponseModel(
|
||||
bool IsPasswordChanged
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Model for verifying the initialization status of the application.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("IsInitialized: {IsInitialized}")]
|
||||
public class InitializationModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the application has been run before, and the super admin account has been created.
|
||||
/// </summary>
|
||||
public bool IsInitialized { get; set; }
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the request model for account password recovery.
|
||||
/// </summary>
|
||||
/// <param name="Username">The username of the account for which to recover the password.</param>
|
||||
/// <param name="TotpCode">The TOTP (Time-Based One-Time Password) code used to recover the password.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record RecoverPasswordRequestModel(
|
||||
string? Username,
|
||||
string? TotpCode
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response model for an account password reset request.
|
||||
/// </summary>
|
||||
/// <param name="IsPasswordReset">Whether the password was reset or not.</param>
|
||||
[DebuggerDisplay("IsPasswordReset: {IsPasswordReset}")]
|
||||
public record RecoverPasswordResponseModel(
|
||||
bool IsPasswordReset
|
||||
);
|
||||
@@ -14,9 +14,9 @@ namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
|
||||
/// <param name="Use2fa">Indicates whether two-factor authentication (2FA) should be enabled for the new account.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
public record RegisterRequestModel(
|
||||
string? Username = null,
|
||||
string? Password = null,
|
||||
string? PasswordConfirm = null,
|
||||
string? RegistrationType = null,
|
||||
string? Username,
|
||||
string? Password,
|
||||
string? PasswordConfirm,
|
||||
string? RegistrationType,
|
||||
bool Use2fa = true
|
||||
);
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.BookLibrary;
|
||||
using Lumina.Presentation.Web.Common.Models.MediaContributors;
|
||||
using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary;
|
||||
using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to add a book.
|
||||
/// </summary>
|
||||
public class AddBookRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the written content metadata of the book.
|
||||
/// </summary>
|
||||
public WrittenContentMetadataModel? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the format of the book (e.g., Hardcover, Paperback), if applicable.
|
||||
/// </summary>
|
||||
public BookFormat? Format { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the edition of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? Edition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the volume or book number in the series, if applicable.
|
||||
/// </summary>
|
||||
public int? VolumeNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the series name, if the book is part of a series.
|
||||
/// </summary>
|
||||
public BookSeriesModel? Series { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ASIN (Amazon Standard Identification Number) of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? ASIN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Goodreads ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? GoodreadsId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Library of Congress Control Number (LCCN) of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? LCCN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the OCLC Number (WorldCat identifier) of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? OCLCNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Open Library ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? OpenLibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the LibraryThing ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? LibraryThingId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Google Books ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? GoogleBooksId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Barnes & Noble ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? BarnesAndNobleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Apple Books ID of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? AppleBooksId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ISBN (International Standard Book Number) of the book.
|
||||
/// </summary>
|
||||
public List<IsbnModel>? ISBNs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of media contributors (actors, directors, etc) starring in this book.
|
||||
/// </summary>
|
||||
public List<MediaContributorModel>? Contributors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this book.
|
||||
/// </summary>
|
||||
public List<BookRatingModel>? Ratings { get; set; }
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class AuthController : Controller
|
||||
// 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(new RegisterRequestModel());
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,10 +91,18 @@ public class AuthController : Controller
|
||||
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>
|
||||
[InitializationCheck]
|
||||
[HttpGet("profile")]
|
||||
public IActionResult Profile()
|
||||
{
|
||||
@@ -118,7 +126,7 @@ public class AuthController : Controller
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs in an new account.
|
||||
/// 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>
|
||||
@@ -167,4 +175,44 @@ public class AuthController : Controller
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,21 @@
|
||||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5012"
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5012"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5012;https://localhost:7112"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5012;https://localhost:7112"
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTPS_PORTS": "8081",
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
},
|
||||
"publishAllPorts": true,
|
||||
"useSSL": true
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json"
|
||||
}
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json"
|
||||
}
|
||||
@@ -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>
|
||||
}
|
||||
@@ -34,11 +34,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button id="btnRecoverPassword" type="button" class="abort-button h-22px w-150px" data-link="@Url.Action("RecoverPassword", "Auth")">Recover Password</button>
|
||||
<button id="btnLogin" type="submit" class="confirm-button h-22px w-100px">Login</button>
|
||||
<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="divTotpCode">
|
||||
<div class="form-row mt-10 hidden" id="div-totp-code">
|
||||
<div class="form-label">
|
||||
<label asp-for="TotpCode">Totp Code</label>
|
||||
</div>
|
||||
@@ -47,7 +47,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button type="submit" id="btnValidateTotp" class="confirm-button h-22px w-100px hidden">Validate Code</button>
|
||||
<button type="submit" id="btn-validate-totp" class="confirm-button h-22px w-100px hidden">Validate Code</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -60,17 +60,17 @@
|
||||
const txtUsername = form.querySelector('[name="Username"]');
|
||||
const txtPassword = form.querySelector('[name="Password"]');
|
||||
const txtTotpCode = form.querySelector('[name="TotpCode"]');
|
||||
const divTotpCode = document.getElementById('divTotpCode');
|
||||
const btnLogin = document.getElementById('btnLogin');
|
||||
const btnRecoverPassword = document.getElementById('btnRecoverPassword');
|
||||
const btnValidateTotp = document.getElementById('btnValidateTotp');
|
||||
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('/auth/login', formData);
|
||||
if (data && data.isTotpRequired) {
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("Login", "Auth")', formData);
|
||||
if (data && data.isTotpRequired === true) {
|
||||
txtUsername.disabled = true;
|
||||
txtPassword.disabled = true;
|
||||
btnLogin.disabled = true;
|
||||
@@ -82,7 +82,7 @@
|
||||
else if (data)
|
||||
window.location.href = data;
|
||||
});
|
||||
document.getElementById('btnRecoverPassword').addEventListener('click', () => {
|
||||
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>
|
||||
}
|
||||
+19
-16
@@ -1,18 +1,21 @@
|
||||
@*
|
||||
/account/register/
|
||||
/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="Account" asp-action="Register" method="post" id="register-account-form" class="inline">
|
||||
<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" />
|
||||
@@ -57,7 +60,7 @@
|
||||
<small class="form-label text-disabled form-description">DescriptionPasswordConfirm</small>
|
||||
</div>
|
||||
<!-- 2FA -->
|
||||
<input type="hidden" id="hiddenUseTwoFa" name="use2fa" value="true">
|
||||
<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">
|
||||
@@ -69,7 +72,7 @@
|
||||
<small class="form-label text-disabled form-description">Description2Fa</small>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<span id="register2FaAttention" class="invalid-feedback w-95 text-center hidden">Password recovery is allowed only if two factor authentication is enabled!</span>
|
||||
<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>
|
||||
@@ -78,10 +81,10 @@
|
||||
</form>
|
||||
<!-- section registration success -->
|
||||
<div class="text-center w-100">
|
||||
<p id="registerSuccess" class="text-light-one w-100 hidden">Account Created</p>
|
||||
<img id="totpImage" class="w-200px h-200px h-align-m mx-auto mt-10 hidden" />
|
||||
<p id="totpMessage" class="text-light-one w-100 hidden">Scan Totp Code</p>
|
||||
<a id="redirectButton" asp-controller="Account" asp-action="Login" class="confirm-button f-14 pt-0 pb-0 h-22px w-80px mt-10 mb-10 mx-auto hidden">Login</a>
|
||||
<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 {
|
||||
@@ -93,10 +96,10 @@
|
||||
const txtPassword = form.querySelector('[name="Password"]');
|
||||
const txtPasswordConfirm = form.querySelector('[name="PasswordConfirm"]');
|
||||
const chkUse2FA = form.querySelector('[name="Use2fa"]');
|
||||
const registerSuccess = document.getElementById('registerSuccess');
|
||||
const redirectButton = document.getElementById('redirectButton');
|
||||
const totpMessage = document.querySelector('#totpMessage');
|
||||
const totpImage = document.querySelector('#totpImage');
|
||||
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,
|
||||
@@ -104,14 +107,14 @@
|
||||
Use2fa: chkUse2FA.checked,
|
||||
RegistrationType: form.querySelector('[name="RegistrationType"]').value
|
||||
};
|
||||
const data = await callApiPostAsync('/account/register', formData);
|
||||
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');
|
||||
redirectButton.classList.replace('hidden', 'block');
|
||||
btnLogin.classList.replace('hidden', 'block');
|
||||
if (chkUse2FA.checked) {
|
||||
totpMessage.classList.remove('hidden');
|
||||
totpMessage.classList.add('block');
|
||||
@@ -124,11 +127,11 @@
|
||||
});
|
||||
document.querySelector('[name="Use2fa"]').addEventListener('change', function () {
|
||||
const isChecked = this.checked;
|
||||
document.querySelector('#register2FaAttention').classList.replace(
|
||||
document.getElementById('#register-two-fa-attention').classList.replace(
|
||||
isChecked ? 'inline' : 'hidden',
|
||||
isChecked ? 'hidden' : 'inline'
|
||||
);
|
||||
document.querySelector('#hiddenUseTwoFa').value = isChecked.toString();
|
||||
document.getElementById('#hidden-use-two-fa').value = isChecked.toString();
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
@using Lumina.Presentation.Web.Common.Enums.Notifications
|
||||
@using Lumina.Presentation.Web.Common.Exceptions
|
||||
@using Lumina.Presentation.Web.Common.Models.FileSystemManagement
|
||||
@using Lumina.Presentation.Web.Common.Models.UI
|
||||
@using Microsoft.AspNetCore.Components
|
||||
@using System.Text.Json
|
||||
@using System.Text
|
||||
|
||||
@@ -1,31 +1,34 @@
|
||||
<!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()
|
||||
<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>
|
||||
</article>
|
||||
</main>
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
|
||||
{
|
||||
<!--Audio player-->
|
||||
<div class="audio-player-container">
|
||||
<video controls
|
||||
@@ -33,15 +36,16 @@
|
||||
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>
|
||||
<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>
|
||||
}
|
||||
</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>
|
||||
<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,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-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>
|
||||
@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-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>
|
||||
@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>
|
||||
|
||||
@@ -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();
|
||||
@@ -62,8 +64,8 @@ async function callApiPostAsync(url, data, options = {}) {
|
||||
// add anti-forgery token if enabled
|
||||
if (finalOptions.useAntiForgery) {
|
||||
const token = document.querySelector('input[name="__RequestVerificationToken"]')?.value;
|
||||
if (token)
|
||||
headers['X-CSRF-TOKEN'] = token;
|
||||
if (token)
|
||||
headers['RequestVerificationToken'] = token;
|
||||
}
|
||||
// make the request
|
||||
const response = await fetch(url, {
|
||||
@@ -71,7 +73,9 @@ async function callApiPostAsync(url, data, options = {}) {
|
||||
headers: headers,
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (!response.ok)
|
||||
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) {
|
||||
@@ -196,7 +200,7 @@ async function updateContent(url, addToHistory) {
|
||||
*/
|
||||
function showBusyIndicator() {
|
||||
//if (ajaxCallCounter === 0)
|
||||
//progressIndicator.classList.remove('hidden');
|
||||
//progressIndicator.classList.remove('hidden');
|
||||
ajaxCallCounter++;
|
||||
}
|
||||
|
||||
@@ -206,7 +210,7 @@ function showBusyIndicator() {
|
||||
function hideBusyIndicator() {
|
||||
ajaxCallCounter--;
|
||||
//if (ajaxCallCounter === 0)
|
||||
//progressIndicator.classList.add('hidden');
|
||||
//progressIndicator.classList.add('hidden');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,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');
|
||||
}
|
||||
|
||||
@@ -355,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');
|
||||
}
|
||||
|
||||
@@ -413,8 +417,10 @@ function toggleAudioPlayerFullHeight() {
|
||||
contentContainer.classList.toggle('audio-player-full-height');
|
||||
}
|
||||
|
||||
audioPlayerFullHeightToggle.addEventListener('click', toggleAudioPlayerFullHeight);
|
||||
audioPlayerClose.addEventListener('click', toggleAudioPlayerVisibility);
|
||||
if (audioPlayerFullHeightToggle)
|
||||
audioPlayerFullHeightToggle.addEventListener('click', toggleAudioPlayerFullHeight);
|
||||
if (audioPlayerClose)
|
||||
audioPlayerClose.addEventListener('click', toggleAudioPlayerVisibility);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user