mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Turns the lowercase comments into sentences.
This commit is contained in:
1 parent
006df1da3a
commit
0019821e87
16 files changed
+38
-38
No files matched your search
+2
-2
@@ -26,10 +26,10 @@ namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Scheduler;
|
||||
/// </summary>
|
||||
public class SchedulerIndexViewEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
// the resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Admin.Scheduler";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// the page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "admin/scheduler";
|
||||
|
||||
private readonly IAntiforgery _antiforgery;
|
||||
|
||||
@@ -40,8 +40,8 @@ public abstract class BaseEndpoint<TRequest, TResponse> : Endpoint<TRequest, TRe
|
||||
/// <returns>An <see cref="IResult"/> that renders the view.</returns>
|
||||
protected IResult View(string viewName, object? model = null, IReadOnlyDictionary<string, object?>? viewData = null)
|
||||
{
|
||||
// store the path of the displayed view in the session, so that the login redirect after the JWT token expires points to it; ignore the login endpoint,
|
||||
// because it is incorrect to be redirected to the login URL, with the login URL as the return URL
|
||||
// Store the path of the displayed view in the session, so that the login redirect after the JWT token expires points to it; ignore the login endpoint,
|
||||
// because it is incorrect to be redirected to the login URL, with the login URL as the return URL.
|
||||
if (HttpContext.Request.Path != "/en-us/auth/login")
|
||||
HttpContext.Session.SetString(HttpContextItemKeys.LAST_DISPLAYED_VIEW, $"{HttpContext.Request.PathBase}{HttpContext.Request.Path}{HttpContext.Request.QueryString}");
|
||||
return new RazorViewResult(viewName, model, viewData);
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class GetThumbnailEndpoint : BaseEndpoint<GetThumbnailRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetThumbnailRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// the thumbnail is proxied through the Web application, so that the request carries the authentication of the current user
|
||||
// The thumbnail is proxied through the Web application, so that the request carries the authentication of the current user.
|
||||
BlobDataDto blob = await _apiHttpClient.GetBlobAsync($"{ApiRoutes.Thumbnails.GET_THUMBNAIL}?path={Uri.EscapeDataString(request.Path!)}&quality={request.Quality}", cancellationToken).ConfigureAwait(false);
|
||||
return Results.File(blob.Data, blob.ContentType);
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ namespace Lumina.Presentation.Web.Core.Endpoints.Home;
|
||||
/// </summary>
|
||||
public class HomeNotFoundViewEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
// the resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Shared.NotFound";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// the page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "shared/not-found";
|
||||
|
||||
private readonly ThemePageRenderer _themePageRenderer;
|
||||
|
||||
+3
-3
@@ -25,12 +25,12 @@ namespace Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.B
|
||||
/// </summary>
|
||||
public class BooksIndexViewEndpoint : BaseEndpoint<GetBooksViewRequest, IResult>
|
||||
{
|
||||
// the resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it
|
||||
// with the configured ResourcesPath, so "Lumina.Presentation.Web.Views.X" resolves to the embedded
|
||||
// "Lumina.Presentation.Web.Core.Resources.Views.X" resource; including "Core" here would insert it twice
|
||||
// "Lumina.Presentation.Web.Core.Resources.Views.X" resource; including "Core" here would insert it twice.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Library.WrittenContentLibrary.BookLibrary.Books.Index";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// the page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "library/written-content-library/book-library/books/index";
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class ThemeAssetsEndpoint : BaseEndpoint<GetThemeAssetRequest, IResult>
|
||||
if (string.IsNullOrWhiteSpace(request.ThemeId) || string.IsNullOrWhiteSpace(request.Path))
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id and the asset path are required.");
|
||||
|
||||
// the API route token is a catch-all ("{*assetPath}"), so the replace target must include the star to match it
|
||||
// The API route token is a catch-all ("{*assetPath}"), so the replace target must include the star to match it.
|
||||
BlobDataDto blob = await _apiHttpClient.GetBlobAsync(
|
||||
ApiRoutes.Themes.GET_THEME_ASSET.Replace("{themeId}", request.ThemeId).Replace("{*assetPath}", request.Path), cancellationToken).ConfigureAwait(false);
|
||||
return Results.File(blob.Data, blob.ContentType);
|
||||
|
||||
+6
-6
@@ -38,7 +38,7 @@ public class SetLanguageEndpoint : BaseEndpoint<SetLanguageRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(SetLanguageRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// store the culture preference in a cookie
|
||||
// Store the culture preference in a cookie.
|
||||
HttpContext.Response.Cookies.Append(
|
||||
CookieRequestCultureProvider.DefaultCookieName,
|
||||
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(request.NewCulture!)),
|
||||
@@ -50,25 +50,25 @@ public class SetLanguageEndpoint : BaseEndpoint<SetLanguageRequest, IResult>
|
||||
Path = "/" // ensure the cookie works across all paths
|
||||
}
|
||||
);
|
||||
// determine the URL to return to, defaulting to the localized home page when no return URL is supplied
|
||||
// Determine the URL to return to, defaulting to the localized home page when no return URL is supplied.
|
||||
string newCulture = request.NewCulture!;
|
||||
string returnUrl = string.IsNullOrEmpty(request.ReturnUrl) ? $"/{newCulture.ToLower()}" : request.ReturnUrl;
|
||||
string currentCulture = Culture;
|
||||
|
||||
// handle the base path, so that the culture replacement matches the URL
|
||||
// Handle the base path, so that the culture replacement matches the URL.
|
||||
if (!string.IsNullOrEmpty(HttpContext.Request.PathBase))
|
||||
returnUrl = returnUrl.Replace(HttpContext.Request.PathBase.Value!, string.Empty, StringComparison.OrdinalIgnoreCase);
|
||||
// replace the current culture segment of the URL with the new one, whether or not a trailing slash is present
|
||||
// Replace the current culture segment of the URL with the new one, whether or not a trailing slash is present.
|
||||
string currentCultureSegment = $"/{currentCulture.ToLower()}";
|
||||
string newCultureSegment = $"/{newCulture.ToLower()}";
|
||||
if (returnUrl.StartsWith(currentCultureSegment, StringComparison.OrdinalIgnoreCase))
|
||||
returnUrl = newCultureSegment + returnUrl[currentCultureSegment.Length..];
|
||||
|
||||
// re-apply the base path if present
|
||||
// Re-apply the base path if present.
|
||||
if (!string.IsNullOrEmpty(HttpContext.Request.PathBase))
|
||||
returnUrl = HttpContext.Request.PathBase.Value + returnUrl;
|
||||
|
||||
// redirect to the target page
|
||||
// Redirect to the target page.
|
||||
return Results.LocalRedirect(returnUrl);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class GetUserSettingsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
UserSettingsDto response = await _apiHttpClient.GetAsync<UserSettingsDto>(ApiRoutes.Users.GET_USER_SETTINGS, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// refresh the per-user theme cache preference from the stored settings, so the handler always applies the latest value
|
||||
// Refresh the per-user theme cache preference from the stored settings, so the handler always applies the latest value.
|
||||
Guid? userId = GetCurrentUserId();
|
||||
if (userId is not null)
|
||||
await _themeCachePreferenceService.SetAsync(userId.Value, response.IsThemeCachingEnabled, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class UpdateUserSettingsEndpoint : BaseEndpoint<UserSettingsDto, IResult>
|
||||
{
|
||||
await _apiHttpClient.PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(ApiRoutes.Users.UPDATE_USER_SETTINGS, request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// keep the per-user theme cache preference in sync with the stored settings, so the handler applies it immediately
|
||||
// Keep the per-user theme cache preference in sync with the stored settings, so the handler applies it immediately.
|
||||
Guid? userId = GetCurrentUserId();
|
||||
if (userId is not null)
|
||||
await _themeCachePreferenceService.SetAsync(userId.Value, request.IsThemeCachingEnabled, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class ChangePasswordEndpoint : BaseEndpoint<ChangePasswordRequest, IResul
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(ChangePasswordRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// assign the currently logged in user as the user for which to change the password
|
||||
// Assign the currently logged in user as the user for which to change the password.
|
||||
ChangePasswordRequest changePasswordRequest = request with { Username = User?.Identity?.Name };
|
||||
ChangePasswordResponse response = await _apiHttpClient.PostAsync<ChangePasswordResponse, ChangePasswordRequest>(ApiRoutes.Authentication.CHANGE_PASSWORD, changePasswordRequest, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
|
||||
+11
-11
@@ -67,9 +67,9 @@ public class LoginEndpoint : BaseEndpoint<LoginRequest, IResult>
|
||||
{
|
||||
try
|
||||
{
|
||||
// attempt API login
|
||||
// Attempt API login.
|
||||
LoginResponse response = await _apiHttpClient.PostAsync<LoginResponse, LoginRequest>(ApiRoutes.Authentication.LOGIN_ACCOUNT, request, cancellationToken).ConfigureAwait(false);
|
||||
// store the received token in a secure cookie
|
||||
// Store the received token in a secure cookie.
|
||||
HttpContext.Response.Cookies.Delete("Token");
|
||||
HttpContext.Response.Cookies.Append("Token", _cryptographyService.Encrypt(response.Token!), new CookieOptions
|
||||
{
|
||||
@@ -80,7 +80,7 @@ public class LoginEndpoint : BaseEndpoint<LoginRequest, IResult>
|
||||
IsEssential = true,
|
||||
SameSite = SameSiteMode.Strict
|
||||
});
|
||||
// tell asp.net we are logged in
|
||||
// Tell ASP.NET we are logged in.
|
||||
List<Claim> claims =
|
||||
[
|
||||
new Claim(ClaimTypes.Name, response.Username!),
|
||||
@@ -89,34 +89,34 @@ public class LoginEndpoint : BaseEndpoint<LoginRequest, IResult>
|
||||
];
|
||||
ClaimsIdentity claimsIdentity = new(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)).ConfigureAwait(false);
|
||||
// get current culture from route data or use default if not set
|
||||
// Get current culture from route data or use default if not set.
|
||||
string currentCulture = Culture;
|
||||
// handle ReturnUrl and ensure it includes the correct culture
|
||||
// Handle ReturnUrl and ensure it includes the correct culture.
|
||||
string redirectUrl;
|
||||
if (!string.IsNullOrEmpty(request.ReturnUrl) && IsLocalUrl(request.ReturnUrl)) // ensure that return URL contains the correct culture
|
||||
redirectUrl = request.ReturnUrl.StartsWith($"/{currentCulture}/") ? request.ReturnUrl : $"/{currentCulture}{request.ReturnUrl}";
|
||||
else
|
||||
{
|
||||
// if no ReturnUrl is provided or it's invalid, use a default URL with respect to base paths
|
||||
// If no ReturnUrl is provided or it's invalid, use a default URL with respect to base paths.
|
||||
redirectUrl = "/";
|
||||
|
||||
// handle reverse proxy scenarios by respecting any base path or forwarded headers
|
||||
// Handle reverse proxy scenarios by respecting any base path or forwarded headers.
|
||||
if (HttpContext.Request.Headers.TryGetValue("X-Forwarded-Prefix", out Microsoft.Extensions.Primitives.StringValues pathBase))
|
||||
redirectUrl = pathBase + redirectUrl;
|
||||
|
||||
// ensure that default redirect contains the correct culture
|
||||
// Ensure that default redirect contains the correct culture.
|
||||
if (!redirectUrl.StartsWith($"/{currentCulture}/"))
|
||||
redirectUrl = $"/{currentCulture}{redirectUrl}";
|
||||
}
|
||||
|
||||
// return success status and redirect URL
|
||||
// Return success status and redirect URL.
|
||||
return JsonSuccess(redirectUrl);
|
||||
}
|
||||
catch (ApiException apiException)
|
||||
{
|
||||
// in this particular case, we DO NOT want to let the exception handling middleware take care of this exception, because when the user has 2FA enabled, the first auth step involves sending
|
||||
// In this particular case, we DO NOT want to let the exception handling middleware 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
|
||||
// and display the form that asks the user for the TOTP code.
|
||||
if (apiException.ProblemDetails is not null && apiException.ProblemDetails.Extensions?.Count > 0 && apiException.ProblemDetails.Extensions.TryGetValue("errors", out JsonElement errorsObj))
|
||||
if (errorsObj is JsonElement jsonElement && jsonElement.ValueKind == JsonValueKind.Object)
|
||||
foreach (JsonProperty error in jsonElement.EnumerateObject())
|
||||
|
||||
+2
-2
@@ -54,10 +54,10 @@ public class LoginViewEndpoint : BaseEndpoint<LoginViewRequest, IResult>
|
||||
public override Task<IResult> ExecuteAsync(LoginViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Dictionary<string, object?> viewData = new() { ["ReturnUrl"] = request.ReturnUrl };
|
||||
// if the user is already logged in, redirect them to the home page
|
||||
// If the user is already logged in, redirect them to the home page.
|
||||
if (User?.Identity?.IsAuthenticated == true)
|
||||
return Task.FromResult(Results.Redirect(_urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED)!));
|
||||
// check if the application is initialized (does contain at least the super user account); if it's not, redirect to registration view
|
||||
// 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")
|
||||
return Task.FromResult(Results.Redirect(_urlService.GetAbsoluteUrl(WebRoutes.Authentication.REGISTER_VIEW)!));
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class LogoutEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// if the user is not logged in, redirect them to the home page
|
||||
// If the user is not logged in, redirect them to the home page.
|
||||
if (User?.Identity?.IsAuthenticated == false)
|
||||
return Results.Redirect(_urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED)!);
|
||||
HttpContext.Response.Cookies.Delete("Token");
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class RecoverPasswordViewEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// if the user is already logged in, redirect them to the home page
|
||||
// If the user is already logged in, redirect them to the home page.
|
||||
if (User?.Identity?.IsAuthenticated == true)
|
||||
return Task.FromResult(Results.Redirect(_urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED)!));
|
||||
RecoverPasswordRequest recoverPasswordRequest = new(Username: null, TotpCode: null);
|
||||
|
||||
+2
-2
@@ -50,9 +50,9 @@ public class RegisterEndpoint : BaseEndpoint<RegisterRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(RegisterRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// call different endpoints based on the view hidden field - registration for normal users, or initial application admin account setup
|
||||
// Call different endpoints based on the view hidden field - registration for normal users, or initial application admin account setup.
|
||||
string endpoint = request.RegistrationType == "Admin" ? ApiRoutes.Initialization.SETUP_APPLICATION : ApiRoutes.Authentication.REGISTER_ACCOUNT;
|
||||
// attempt API registration
|
||||
// Attempt API registration.
|
||||
RegisterResponse response = await _apiHttpClient.PostAsync<RegisterResponse, RegisterRequest>(endpoint, request, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class RegisterViewEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// check if this is the initial super admin setup
|
||||
// Check if this is the initial super admin setup.
|
||||
string? isPendingSuperAdminSetup = HttpContext.Session.GetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP);
|
||||
string registrationType = isPendingSuperAdminSetup == "true" ? "Admin" : "User";
|
||||
Dictionary<string, object?> viewData = new() { ["RegistrationType"] = registrationType };
|
||||
|
||||
Reference in new issue
Block a user