Allow unauthorized users to search and spectate.
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
<a href="">Home</a>
|
||||
</p>
|
||||
|
||||
<AuthorizeView>
|
||||
<p>
|
||||
<a href="search">Search</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="search">Search</a>
|
||||
</p>
|
||||
|
||||
<AuthorizeView>
|
||||
<p>
|
||||
<button class="href" @onclick="CreateSession">Create</button>
|
||||
</p>
|
||||
|
||||
@@ -56,9 +56,16 @@ else
|
||||
if (this.session != null)
|
||||
{
|
||||
var state = await authenticationState;
|
||||
var accountId = state.User.Claims.First(c => c.Type == ClaimTypes.Name).Value;
|
||||
this.perspective = accountId == session.Player1 ? WhichPlayer.Player1 : WhichPlayer.Player2;
|
||||
this.isSpectating = !(accountId == this.session.Player1 || accountId == this.session.Player2);
|
||||
var accountId = state.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
|
||||
if (accountId == null)
|
||||
{
|
||||
this.isSpectating = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.perspective = accountId == session.Player1 ? WhichPlayer.Player1 : WhichPlayer.Player2;
|
||||
this.isSpectating = !(accountId == this.session.Player1 || accountId == this.session.Player2);
|
||||
}
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
@@ -74,9 +74,11 @@
|
||||
<div class="player-area">
|
||||
@if (Perspective == WhichPlayer.Player2 && string.IsNullOrEmpty(Session.Player2))
|
||||
{
|
||||
<div class="place-self-center">
|
||||
<button @onclick="OnClickJoinGameInternal">Join Game</button>
|
||||
</div>
|
||||
<AuthorizeView>
|
||||
<div class="place-self-center">
|
||||
<button @onclick="OnClickJoinGameInternal">Join Game</button>
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -115,23 +115,19 @@
|
||||
{
|
||||
var pieceBeingMoved = Session.BoardState.Board[selectedBoardPosition];
|
||||
var isPromotedAlready = pieceBeingMoved != null && pieceBeingMoved.IsPromoted;
|
||||
Console.WriteLine("Is promoted? {0}", isPromotedAlready);
|
||||
// Moving to an empty space or capturing an opponent's piece.
|
||||
if (!isPromotedAlready && (IsWithinPromoteArea(position) || IsWithinPromoteArea(selectedBoardPosition)))
|
||||
{
|
||||
Console.WriteLine("Prompt!");
|
||||
moveTo = position;
|
||||
showPromotePrompt = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var success = await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, position, false));
|
||||
Console.WriteLine("Success? {0}", success);
|
||||
if (!success)
|
||||
{
|
||||
selectedBoardPosition = null;
|
||||
showError = true;
|
||||
Console.WriteLine("Show error");
|
||||
}
|
||||
}
|
||||
StateHasChanged();
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
@using System.Net
|
||||
@inject ShogiApi ShogiApi
|
||||
|
||||
<GameBoardPresentation IsSpectating="true"
|
||||
Perspective="WhichPlayer.Player2"
|
||||
Session="Session"
|
||||
OnClickJoinGame="OnClickJoinGame" />
|
||||
<Stretch style="position: relative;">
|
||||
<GameBoardPresentation IsSpectating="true"
|
||||
Perspective="WhichPlayer.Player2"
|
||||
Session="Session"
|
||||
OnClickJoinGame="OnClickJoinGame" />
|
||||
</Stretch>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
|
||||
@@ -13,14 +13,12 @@
|
||||
<span></span>
|
||||
</row>
|
||||
<hr />
|
||||
<AuthorizeView>
|
||||
@foreach (var session in allSessions)
|
||||
{
|
||||
<row>
|
||||
<GameBrowserEntry Session="session" OnSessionDeleted="FetchSessions" />
|
||||
</row>
|
||||
}
|
||||
</AuthorizeView>
|
||||
@foreach (var session in allSessions)
|
||||
{
|
||||
<row>
|
||||
<GameBrowserEntry Session="session" OnSessionDeleted="FetchSessions" />
|
||||
</row>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (allSessions.Length == 0)
|
||||
@@ -40,9 +38,10 @@
|
||||
async Task FetchSessions()
|
||||
{
|
||||
var sessions = await ShogiApi.GetAllSessionsMetadata();
|
||||
Console.WriteLine("Session count {0}", sessions.Length);
|
||||
if (sessions != null)
|
||||
{
|
||||
this.allSessions = sessions.ToArray();
|
||||
this.allSessions = sessions;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,39 +3,39 @@
|
||||
@inject ShogiApi Api
|
||||
|
||||
<gameBrowserEntry>
|
||||
<AuthorizeView>
|
||||
@if (showDeletePrompt)
|
||||
{
|
||||
<modal class="PrimaryTheme ThemeVariant--Contrast">
|
||||
<div style="display: flex; gap: 1rem; justify-content: flex-end;">
|
||||
@if (showDeleteError)
|
||||
{
|
||||
<p style="color: darkred;">An error occurred.</p>
|
||||
<div style="flex: 1;" />
|
||||
<button @onclick="HideModal">Cancel</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Do you wish to delete this session?</p>
|
||||
<div style="flex: 1;" />
|
||||
<button @onclick="HideModal">No</button>
|
||||
<button @onclick="DeleteSession">Yes</button>
|
||||
}
|
||||
</div>
|
||||
</modal>
|
||||
}
|
||||
@if (showDeletePrompt)
|
||||
{
|
||||
<modal class="PrimaryTheme ThemeVariant--Contrast">
|
||||
<div style="display: flex; gap: 1rem; justify-content: flex-end;">
|
||||
@if (showDeleteError)
|
||||
{
|
||||
<p style="color: darkred;">An error occurred.</p>
|
||||
<div style="flex: 1;" />
|
||||
<button @onclick="HideModal">Cancel</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Do you wish to delete this session?</p>
|
||||
<div style="flex: 1;" />
|
||||
<button @onclick="HideModal">No</button>
|
||||
<button @onclick="DeleteSession">Yes</button>
|
||||
}
|
||||
</div>
|
||||
</modal>
|
||||
}
|
||||
|
||||
<div>
|
||||
<a href="play/@Session.SessionId">@Session.Player1</a>
|
||||
</div>
|
||||
@if (string.IsNullOrEmpty(Session.Player2))
|
||||
{
|
||||
<span>1 / 2</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Full</span>
|
||||
}
|
||||
<div>
|
||||
<a href="play/@Session.SessionId">@Session.Player1</a>
|
||||
</div>
|
||||
@if (string.IsNullOrEmpty(Session.Player2))
|
||||
{
|
||||
<span>1 / 2</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Full</span>
|
||||
}
|
||||
<AuthorizeView>
|
||||
@if (context.User.Identity?.Name == Session.Player1)
|
||||
{
|
||||
<IconButton OnClick="() => showDeletePrompt = true">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@attribute [Authorize]
|
||||
@page "/play/{sessionId}"
|
||||
@page "/play/{sessionId}"
|
||||
|
||||
@inject GameHubNode node
|
||||
|
||||
@@ -8,9 +7,7 @@
|
||||
return;
|
||||
}
|
||||
<main class="PrimaryTheme">
|
||||
<AuthorizeView>
|
||||
<GameBoard SessionId="@SessionId" />
|
||||
</AuthorizeView>
|
||||
<GameBoard SessionId="@SessionId" />
|
||||
</main>
|
||||
|
||||
@code {
|
||||
|
||||
Reference in New Issue
Block a user