36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using PlotLine.Services;
|
|
using PlotLine.ViewModels;
|
|
|
|
namespace PlotLine.Controllers;
|
|
|
|
[AllowAnonymous]
|
|
[Route("word-companion")]
|
|
public sealed class WordCompanionHostController(
|
|
ICurrentUserService currentUser,
|
|
IAuthorizationService authorization,
|
|
ILogger<WordCompanionHostController> logger) : Controller
|
|
{
|
|
[HttpGet("")]
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var isAdmin = currentUser.IsAuthenticated
|
|
&& (await authorization.AuthorizeAsync(User, "AdminOnly")).Succeeded;
|
|
logger.LogInformation(
|
|
"Serving Word Companion host. IsAuthenticated={IsAuthenticated} UserID={UserID} IsAdmin={IsAdmin}",
|
|
currentUser.IsAuthenticated,
|
|
currentUser.UserId,
|
|
isAdmin);
|
|
|
|
return View(new WordCompanionHostViewModel
|
|
{
|
|
IsAuthenticated = currentUser.IsAuthenticated,
|
|
IsAdmin = isAdmin,
|
|
UserID = currentUser.UserId,
|
|
DisplayName = currentUser.DisplayName,
|
|
LoginUrl = Url.Action("Login", "Account", new { returnUrl = "/word-companion" }) ?? "/Account/Login?returnUrl=%2Fword-companion"
|
|
});
|
|
}
|
|
}
|