mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16: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
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Api.Common.Routes.Maintenance;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/initialization</c> route.
|
||||
/// </summary>
|
||||
public class CheckInitializationEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckInitializationEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public CheckInitializationEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Initialization.CHECK_INITIALIZATION);
|
||||
Version(1);
|
||||
AllowAnonymous();
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the initialization status of the application (if the Admin account exists).
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
InitializationResponse result = await _sender.Send(new CheckInitializationQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return await Task.FromResult(TypedResults.Ok(result));
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="CheckInitializationEndpoint"/> API endpoint, for Swagger.
|
||||
/// </summary>
|
||||
public class CheckInitializationEndpointSummary : Summary<CheckInitializationEndpoint>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckInitializationEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public CheckInitializationEndpointSummary()
|
||||
{
|
||||
Summary = "Checks the initialization status of the application.";
|
||||
Description = "Checks the initialization status of the application (if the Admin account exists).";
|
||||
|
||||
Response<InitializationResponse>(200, "The application initialization status is returned.");
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Lumina.Presentation.Api.Common.Routes.Maintenance;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/initialization</c> route.
|
||||
/// </summary>
|
||||
public class SetupApplicationEndpoint : BaseEndpoint<RegistrationRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetupApplicationEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public SetupApplicationEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.POST);
|
||||
Routes(ApiRoutes.Initialization.SETUP_APPLICATION);
|
||||
Version(1);
|
||||
AllowAnonymous();
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the initial application setup, including creating the Admin account.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Admin user to be added.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(RegistrationRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<RegistrationResponse> result = await _sender.Send(request.ToSetupCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{Api.Common.Routes.UsersManagement.ApiRoutes.Users.GET_USER_BY_ID}/{result.Value.Id}", result.Value), Problem);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="SetupApplicationEndpoint"/> API endpoint, for Swagger.
|
||||
/// </summary>
|
||||
public class SetupApplicationEndpointSummary : Summary<SetupApplicationEndpoint, RegistrationRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetupApplicationEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public SetupApplicationEndpointSummary()
|
||||
{
|
||||
Summary = "Performs the initial application setup.";
|
||||
Description = "Performs the initial application setup, including creating the Admin account.";
|
||||
|
||||
RequestParam(r => r.Username, "The desired username for the new account.");
|
||||
RequestParam(r => r.Password, "The password for the new account.");
|
||||
RequestParam(r => r.PasswordConfirm, "The confirmation of the entered password, used to ensure consistency.");
|
||||
RequestParam(r => r.Use2fa, "Indicates whether two-factor authentication (2FA) should be enabled for the new account.");
|
||||
|
||||
Response(200, "The Admin account of the application is returned.");
|
||||
Response<ProblemDetails>(422, "The request did not pass validation checks.", "application/problem+json");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.Common.Routes.FileSystemManagement;
|
||||
using Lumina.Presentation.Api.Common.Routes.Maintenance;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
Reference in new issue
Block a user