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