[backend/razor] Add login button to footer

This commit is contained in:
Laura Hausmann 2024-09-18 23:37:38 +02:00
parent 797001233c
commit 898ea4d26c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
9 changed files with 28 additions and 9 deletions

View file

@ -112,6 +112,7 @@ public static partial class HttpContextExtensions
{ {
private const string Key = "session"; private const string Key = "session";
private const string MastodonKey = "masto-session"; private const string MastodonKey = "masto-session";
private const string HideFooterKey = "hide-login-footer";
internal static void SetSession(this HttpContext ctx, Session session) 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"); 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);
} }

View file

@ -1,3 +1,4 @@
using Iceshrimp.Backend.Core.Middleware;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
@ -13,6 +14,7 @@ public class ErrorModel : PageModel
public void OnGet() public void OnGet()
{ {
Request.HttpContext.HideFooter();
RequestId = HttpContext.TraceIdentifier; RequestId = HttpContext.TraceIdentifier;
} }
} }

View file

@ -17,8 +17,6 @@
<h1>@Model.InstanceName</h1> <h1>@Model.InstanceName</h1>
<p>@Model.InstanceDescription</p> <p>@Model.InstanceDescription</p>
<a href="/login">Login</a>
@if (Model.ContactEmail != null) @if (Model.ContactEmail != null)
{ {
<span>| <a href="mailto:@Model.ContactEmail">Contact instance administrators</a></span> <span>| <a href="mailto:@Model.ContactEmail">Contact instance administrators</a></span>

View file

@ -44,8 +44,6 @@ public class NoteModel(
InstanceName = await meta.Get(MetaEntity.InstanceName) ?? InstanceName; 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: thread view (respect public preview settings - don't show remote replies if set to restricted or lower)
//TODO: emoji //TODO: emoji

View file

@ -31,6 +31,8 @@ public class QueueModel(DatabaseContext db, QueueService queueSvc) : PageModel
if (!await db.Sessions.AnyAsync(p => p.Token == cookie && p.Active && p.User.IsAdmin)) if (!await db.Sessions.AnyAsync(p => p.Token == cookie && p.Active && p.User.IsAdmin))
return Redirect("/login"); return Redirect("/login");
Request.HttpContext.HideFooter();
if (queue == null) if (queue == null)
{ {
Jobs = await db.Jobs.OrderByDescending(p => p.LastUpdatedAt).Take(20).ToListAsync(); Jobs = await db.Jobs.OrderByDescending(p => p.LastUpdatedAt).Take(20).ToListAsync();

View file

@ -27,6 +27,8 @@ public class QueueJobModel(DatabaseContext db) : PageModel
if (!await db.Sessions.AnyAsync(p => p.Token == cookie && p.Active && p.User.IsAdmin)) if (!await db.Sessions.AnyAsync(p => p.Token == cookie && p.Active && p.User.IsAdmin))
return Redirect("/login"); return Redirect("/login");
Request.HttpContext.HideFooter();
Job = await db.Jobs.FirstOrDefaultAsync(p => p.Id == id) ?? Job = await db.Jobs.FirstOrDefaultAsync(p => p.Id == id) ??
throw GracefulException.NotFound($"Job {id} not found"); throw GracefulException.NotFound($"Job {id} not found");
return Page(); return Page();

View file

@ -1,5 +1,6 @@
@inject IOptions<Config.InstanceSection> Instance @inject IOptions<Config.InstanceSection> Instance
@using Iceshrimp.Backend.Core.Configuration @using Iceshrimp.Backend.Core.Configuration
@using Iceshrimp.Backend.Core.Middleware
@using Microsoft.Extensions.Options @using Microsoft.Extensions.Options
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -18,6 +19,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())
{
<a href="/login?rd=@(Context.Request.Path.ToUriComponent())">Login</a>
}
</span>
</footer> </footer>
</body> </body>
</html> </html>

View file

@ -1 +1,3 @@
 .float-right {
float: right;
}

View file

@ -40,7 +40,6 @@ public class UserModel(
InstanceName = await meta.Get(MetaEntity.InstanceName) ?? InstanceName; 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: user note view (respect public preview settings - don't show renotes of remote notes if set to restricted or lower)
//TODO: emoji //TODO: emoji