98 lines
2.8 KiB
Plaintext
98 lines
2.8 KiB
Plaintext
@using RpgRoller.Api
|
|
@using RpgRoller.Components.Pages.HomeControls
|
|
@using RpgRoller.Services
|
|
@attribute [ExcludeFromCodeCoverage]
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<base href="@BaseHref"/>
|
|
<title>RpgRoller</title>
|
|
<link rel="stylesheet" href="@Assets["styles.css"]"/>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;500;600;700&family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&display=swap" rel="stylesheet">
|
|
@if (UseInteractiveApp)
|
|
{
|
|
<HeadOutlet @rendermode="@(new InteractiveServerRenderMode(prerender: false))"/>
|
|
}
|
|
</head>
|
|
<body>
|
|
@if (UseStaticAuthPage)
|
|
{
|
|
<StaticAuthPage StatusMessage="@AuthStatusMessage" StatusIsError="@AuthStatusIsError"/>
|
|
}
|
|
else
|
|
{
|
|
<Routes @rendermode="@(new InteractiveServerRenderMode(prerender: false))"/>
|
|
}
|
|
<script src="js/rpgroller-api.js"></script>
|
|
@if (UseInteractiveApp)
|
|
{
|
|
<script src="_framework/blazor.web.js"></script>
|
|
}
|
|
</body>
|
|
</html>
|
|
|
|
@code {
|
|
[Inject]
|
|
private IGameService GameService { get; set; } = null!;
|
|
|
|
[CascadingParameter]
|
|
private HttpContext? HttpContext { get; set; }
|
|
|
|
private bool UseInteractiveApp => !UseStaticAuthPage;
|
|
|
|
private bool UseStaticAuthPage => IsRootRequest && !HasAuthenticatedSession;
|
|
|
|
private bool IsRootRequest
|
|
{
|
|
get
|
|
{
|
|
var path = HttpContext?.Request.Path.Value;
|
|
return string.IsNullOrWhiteSpace(path) || string.Equals(path, "/", StringComparison.Ordinal);
|
|
}
|
|
}
|
|
|
|
private bool HasAuthenticatedSession
|
|
{
|
|
get
|
|
{
|
|
if (HttpContext is null)
|
|
return false;
|
|
|
|
var sessionToken = HttpContext.Request.Cookies[SessionCookie.Name];
|
|
return !string.IsNullOrWhiteSpace(sessionToken) && GameService.GetUserBySession(sessionToken) is not null;
|
|
}
|
|
}
|
|
|
|
private string? AuthStatusMessage => ReadAuthQueryValue("message");
|
|
|
|
private bool AuthStatusIsError => string.Equals(ReadAuthQueryValue("kind"), "error", StringComparison.OrdinalIgnoreCase);
|
|
|
|
private string BaseHref
|
|
{
|
|
get
|
|
{
|
|
var pathBase = HttpContext?.Request.PathBase.Value;
|
|
if (string.IsNullOrWhiteSpace(pathBase))
|
|
return "/";
|
|
|
|
return pathBase.EndsWith('/') ? pathBase : $"{pathBase}/";
|
|
}
|
|
}
|
|
|
|
private string? ReadAuthQueryValue(string key)
|
|
{
|
|
if (!UseStaticAuthPage || HttpContext is null)
|
|
return null;
|
|
|
|
var value = HttpContext.Request.Query[key];
|
|
return value.Count > 0 ? value[0] : null;
|
|
}
|
|
|
|
}
|