[backend/razor] Show login button when displaying public preview disabled error page
This commit is contained in:
parent
1d4ddb1190
commit
9789c8452e
8 changed files with 25 additions and 15 deletions
|
@ -30,8 +30,7 @@ public class RedirectController(IOptionsSnapshot<Config.SecuritySection> config,
|
|||
{
|
||||
var localUser = HttpContext.GetUser();
|
||||
if (config.Value.PublicPreview == Enums.PublicPreview.Lockdown && localUser == null)
|
||||
throw GracefulException.Forbidden("Public preview is disabled on this instance.",
|
||||
"The instance administrator has intentionally disabled this feature for privacy reasons.");
|
||||
throw new PublicPreviewDisabledException();
|
||||
|
||||
var user = await db.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id) ??
|
||||
throw GracefulException.NotFound("User not found");
|
||||
|
|
|
@ -290,7 +290,7 @@ public static class ServiceExtensions
|
|||
{
|
||||
context.HttpContext.Response.StatusCode = 429;
|
||||
context.HttpContext.Response.ContentType = "application/json";
|
||||
var res = new ErrorResponse
|
||||
var res = new ErrorResponse(new Exception())
|
||||
{
|
||||
Error = "Too Many Requests",
|
||||
StatusCode = 429,
|
||||
|
|
|
@ -92,7 +92,7 @@ public class ErrorHandlerMiddleware(
|
|||
}
|
||||
else
|
||||
{
|
||||
var error = new ErrorResponse
|
||||
var error = new ErrorResponse(e)
|
||||
{
|
||||
StatusCode = ctx.Response.StatusCode,
|
||||
Error = verbosity >= ExceptionVerbosity.Basic ? ce.Error : ce.StatusCode.ToString(),
|
||||
|
@ -121,7 +121,7 @@ public class ErrorHandlerMiddleware(
|
|||
ctx.Response.StatusCode = 500;
|
||||
ctx.Response.Headers.RequestId = ctx.TraceIdentifier;
|
||||
|
||||
var error = new ErrorResponse
|
||||
var error = new ErrorResponse(e)
|
||||
{
|
||||
StatusCode = 500,
|
||||
Error = "Internal Server Error",
|
||||
|
@ -277,6 +277,10 @@ public class InstanceBlockedException(string uri, string? host = null)
|
|||
public string Uri => uri;
|
||||
}
|
||||
|
||||
public class PublicPreviewDisabledException()
|
||||
: GracefulException(HttpStatusCode.Forbidden, "Public preview is disabled on this instance.",
|
||||
"The instance administrator has intentionally disabled this feature for privacy reasons.");
|
||||
|
||||
public class ValidationException(
|
||||
HttpStatusCode statusCode,
|
||||
string error,
|
||||
|
|
|
@ -41,8 +41,7 @@ public class NoteModel(
|
|||
return Partial("Shared/FrontendSPA");
|
||||
|
||||
if (security.Value.PublicPreview == Enums.PublicPreview.Lockdown)
|
||||
throw GracefulException.Forbidden("Public preview is disabled on this instance.",
|
||||
"The instance administrator has intentionally disabled this feature for privacy reasons.");
|
||||
throw new PublicPreviewDisabledException();
|
||||
|
||||
InstanceName = await meta.Get(MetaEntity.InstanceName) ?? InstanceName;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
@page
|
||||
@using Iceshrimp.Backend.Core.Configuration
|
||||
@using Iceshrimp.Backend.Core.Middleware
|
||||
@using Microsoft.Extensions.Options
|
||||
@model ErrorPageModel
|
||||
@inject IOptions<Config.InstanceSection> Instance
|
||||
|
@ -60,6 +61,12 @@
|
|||
</p>
|
||||
<footer>
|
||||
<strong>Iceshrimp.NET</strong> v@(Instance.Value.Version)
|
||||
@if (Model.Error.Exception is PublicPreviewDisabledException)
|
||||
{
|
||||
<span class="float-right">
|
||||
<a href="/login?rd=@(Request.Path.ToUriComponent())">Login</a>
|
||||
</span>
|
||||
}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -20,12 +20,12 @@
|
|||
@await RenderSectionAsync("scripts", false)
|
||||
<footer>
|
||||
<strong>Iceshrimp.NET</strong> v@(Instance.Value.Version)
|
||||
<span class="float-right">
|
||||
@if (!Context.ShouldHideFooter())
|
||||
{
|
||||
@if (!Context.ShouldHideFooter())
|
||||
{
|
||||
<span class="float-right">
|
||||
<a href="/login?rd=@(Context.Request.Path.ToUriComponent())">Login</a>
|
||||
}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -39,8 +39,7 @@ public class UserModel(
|
|||
return Partial("Shared/FrontendSPA");
|
||||
|
||||
if (security.Value.PublicPreview == Enums.PublicPreview.Lockdown)
|
||||
throw GracefulException.Forbidden("Public preview is disabled on this instance.",
|
||||
"The instance administrator has intentionally disabled this feature for privacy reasons.");
|
||||
throw new PublicPreviewDisabledException();
|
||||
|
||||
InstanceName = await meta.Get(MetaEntity.InstanceName) ?? InstanceName;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using JI = System.Text.Json.Serialization.JsonIgnoreAttribute;
|
|||
namespace Iceshrimp.Shared.Schemas.Web;
|
||||
|
||||
[XmlRoot("Error")]
|
||||
public class ErrorResponse
|
||||
public class ErrorResponse(Exception exception)
|
||||
{
|
||||
[XmlElement("Status")] public required int StatusCode { get; set; }
|
||||
[XmlElement("Error")] public required string Error { get; set; }
|
||||
|
@ -37,6 +37,8 @@ public class ErrorResponse
|
|||
public string? Source { get; set; }
|
||||
|
||||
[XmlElement("RequestId")] public required string RequestId { get; set; }
|
||||
|
||||
[JI] [XmlIgnore] public Exception Exception => exception;
|
||||
}
|
||||
|
||||
public class XmlValidationError
|
||||
|
|
Loading…
Add table
Reference in a new issue