@page
@using AutheliaMultiDomainProxy.Backend
@using System.Web
@model IndexModel
@{
	// Check if we are on an allowed domain
	if (Vars.PermittedDomains.All(p => Request.Host.Host != $"{Vars.AuthProxySubdomain}.{p}")) {
		Layout = null;
		Response.Clear();
		Response.StatusCode = StatusCodes.Status421MisdirectedRequest;
		return;
	}

	ViewData["Title"] = "Home";

	var authStatus = AuthHelpers.IsAuthenticated(Request.Cookies);
}

<div class="text-center">
	<h1 class="display-4">Welcome</h1>
	@if (authStatus is { isAuthenticated: true,user: { } }) {
		<p>
			You are currently <span class="badge bg-success">authenticated as @authStatus.user</span>
		</p>

		<form method="POST" action="/api/logout">
			<button type="submit" class="btn btn-danger">Log out</button>
		</form>
	}
	else if (authStatus.isAuthenticated) {
		<p>You are currently <span class="badge bg-success">authenticated</span> (no username known, no actions available)</p>
	}
	else {
		<p>You are currently <span class="badge bg-danger">not authenticated</span></p>
		<a href="https://@Vars.AuthProxySubdomain.@Vars.UpstreamPrimaryDomain/api/cookieproxy_stage_one/?tgt=@HttpUtility.UrlEncode($"https://{Request.Host.Host}")" class="btn btn-success">Log in</a>
	}
</div>
