[backend/razor] Add login button to footer
This commit is contained in:
parent
797001233c
commit
898ea4d26c
9 changed files with 28 additions and 9 deletions
|
@ -110,8 +110,9 @@ public class AuthenticateAttribute(params string[] scopes) : Attribute
|
|||
|
||||
public static partial class HttpContextExtensions
|
||||
{
|
||||
private const string Key = "session";
|
||||
private const string MastodonKey = "masto-session";
|
||||
private const string Key = "session";
|
||||
private const string MastodonKey = "masto-session";
|
||||
private const string HideFooterKey = "hide-login-footer";
|
||||
|
||||
internal static void SetSession(this HttpContext ctx, Session session)
|
||||
{
|
||||
|
@ -149,4 +150,12 @@ public static partial class HttpContextExtensions
|
|||
{
|
||||
return ctx.GetUser() ?? throw new GracefulException("Failed to get user from HttpContext");
|
||||
}
|
||||
|
||||
public static bool ShouldHideFooter(this HttpContext ctx)
|
||||
{
|
||||
ctx.Items.TryGetValue(HideFooterKey, out var auth);
|
||||
return auth is true;
|
||||
}
|
||||
|
||||
public static void HideFooter(this HttpContext ctx) => ctx.Items.Add(HideFooterKey, true);
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
|
@ -13,6 +14,7 @@ public class ErrorModel : PageModel
|
|||
|
||||
public void OnGet()
|
||||
{
|
||||
Request.HttpContext.HideFooter();
|
||||
RequestId = HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
|
@ -17,8 +17,6 @@
|
|||
<h1>@Model.InstanceName</h1>
|
||||
<p>@Model.InstanceDescription</p>
|
||||
|
||||
<a href="/login">Login</a>
|
||||
|
||||
@if (Model.ContactEmail != null)
|
||||
{
|
||||
<span>| <a href="mailto:@Model.ContactEmail">Contact instance administrators</a></span>
|
||||
|
|
|
@ -44,8 +44,6 @@ public class NoteModel(
|
|||
|
||||
InstanceName = await meta.Get(MetaEntity.InstanceName) ?? InstanceName;
|
||||
|
||||
//TODO: redirect to login (with route as url param) when public preview is disabled
|
||||
//TODO: login button
|
||||
//TODO: thread view (respect public preview settings - don't show remote replies if set to restricted or lower)
|
||||
//TODO: emoji
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ public class QueueModel(DatabaseContext db, QueueService queueSvc) : PageModel
|
|||
return Redirect("/login");
|
||||
if (!await db.Sessions.AnyAsync(p => p.Token == cookie && p.Active && p.User.IsAdmin))
|
||||
return Redirect("/login");
|
||||
|
||||
Request.HttpContext.HideFooter();
|
||||
|
||||
if (queue == null)
|
||||
{
|
||||
|
@ -127,4 +129,4 @@ public class QueueModel(DatabaseContext db, QueueService queueSvc) : PageModel
|
|||
public required string Name { get; init; }
|
||||
public required IReadOnlyDictionary<Job.JobStatus, int> JobCounts { get; init; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public class QueueJobModel(DatabaseContext db) : PageModel
|
|||
return Redirect("/login");
|
||||
if (!await db.Sessions.AnyAsync(p => p.Token == cookie && p.Active && p.User.IsAdmin))
|
||||
return Redirect("/login");
|
||||
|
||||
Request.HttpContext.HideFooter();
|
||||
|
||||
Job = await db.Jobs.FirstOrDefaultAsync(p => p.Id == id) ??
|
||||
throw GracefulException.NotFound($"Job {id} not found");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
@inject IOptions<Config.InstanceSection> Instance
|
||||
@using Iceshrimp.Backend.Core.Configuration
|
||||
@using Iceshrimp.Backend.Core.Middleware
|
||||
@using Microsoft.Extensions.Options
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
@ -18,6 +19,12 @@
|
|||
@await RenderSectionAsync("scripts", false)
|
||||
<footer>
|
||||
<strong>Iceshrimp.NET</strong> v@(Instance.Value.Version)
|
||||
<span class="float-right">
|
||||
@if (!Context.ShouldHideFooter())
|
||||
{
|
||||
<a href="/login?rd=@(Context.Request.Path.ToUriComponent())">Login</a>
|
||||
}
|
||||
</span>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -1 +1,3 @@
|
|||
|
||||
.float-right {
|
||||
float: right;
|
||||
}
|
|
@ -40,7 +40,6 @@ public class UserModel(
|
|||
|
||||
InstanceName = await meta.Get(MetaEntity.InstanceName) ?? InstanceName;
|
||||
|
||||
//TODO: login button
|
||||
//TODO: user note view (respect public preview settings - don't show renotes of remote notes if set to restricted or lower)
|
||||
//TODO: emoji
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue