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 logger) : Controller { [HttpGet("")] public async Task 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" }); } }