26 lines
1.1 KiB
C#
26 lines
1.1 KiB
C#
using Htmx.ApiDemo.Data;
|
|
using Microsoft.AspNetCore.Antiforgery;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Htmx.ApiDemo.Templates;
|
|
|
|
public sealed class Login : LoginBase
|
|
{
|
|
private readonly byte[] _errorData;
|
|
private readonly byte[] _afTokenData;
|
|
|
|
public Login(string? errorMessage = null, string? afToken = null)
|
|
{
|
|
_errorData = string.IsNullOrEmpty(errorMessage)
|
|
? []
|
|
: $"""<div class="rounded-md bg-destructive/15 px-4 py-3 text-sm text-destructive border border-destructive/30">{System.Web.HttpUtility.HtmlEncode(errorMessage)}</div>""".ToUtf8Bytes();
|
|
|
|
_afTokenData = string.IsNullOrEmpty(afToken)
|
|
? []
|
|
: $"""<input type="hidden" name="__RequestVerificationToken" value="{System.Web.HttpUtility.HtmlAttributeEncode(afToken)}" />""".ToUtf8Bytes();
|
|
}
|
|
|
|
protected override void RenderErrorMessage(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_errorData);
|
|
protected override void RenderAntiforgeryToken(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_afTokenData);
|
|
} |