before deleting Rules

This commit is contained in:
2021-05-08 10:26:04 -05:00
parent 05a9c71499
commit f8f779e84c
80 changed files with 1109 additions and 832 deletions

View File

@@ -1,4 +1,5 @@
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Managers;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
using Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages;
using Microsoft.AspNetCore.Authorization;
@@ -14,17 +15,20 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
public class GameController : ControllerBase
{
private readonly IGameboardRepositoryManager manager;
private readonly ISocketCommunicationManager communicationManager;
private readonly IGameboardRepository repository;
public GameController(
IGameboardRepository repository,
IGameboardRepositoryManager manager)
IGameboardRepositoryManager manager,
ISocketCommunicationManager communicationManager)
{
this.manager = manager;
this.communicationManager = communicationManager;
this.repository = repository;
}
[Route("JoinCode")]
[HttpPost("JoinCode")]
public async Task<IActionResult> PostGameInvitation([FromBody] PostGameInvitation request)
{
var userName = HttpContext.User.Claims.First(c => c.Type == "preferred_username").Value;
@@ -41,7 +45,7 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
}
[AllowAnonymous]
[Route("GuestJoinCode")]
[HttpPost("GuestJoinCode")]
public async Task<IActionResult> PostGuestGameInvitation([FromBody] PostGuestGameInvitation request)
{
@@ -57,5 +61,26 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
return new UnauthorizedResult();
}
}
// TODO: Use JWT tokens for guests so they can authenticate and use API routes, too.
//[Route("")]
//public async Task<IActionResult> PostSession([FromBody] PostSession request)
//{
// var model = new Models.Session(request.Name, request.IsPrivate, request.Player1, request.Player2);
// var success = await repository.CreateSession(model);
// if (success)
// {
// var message = new ServiceModels.Socket.Messages.CreateGameResponse(ServiceModels.Socket.Types.ClientAction.CreateGame)
// {
// Game = model.ToServiceModel(),
// PlayerName =
// }
// var task = request.IsPrivate
// ? communicationManager.BroadcastToPlayers(response, userName)
// : communicationManager.BroadcastToAll(response);
// return new CreatedResult("", null);
// }
// return new ConflictResult();
//}
}
}

View File

@@ -1,8 +1,10 @@
using Gameboard.ShogiUI.Sockets.Managers;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
using Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
@@ -13,18 +15,24 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
[ApiController]
public class SocketController : ControllerBase
{
private readonly ILogger<SocketController> logger;
private readonly ISocketTokenManager tokenManager;
private readonly IGameboardRepositoryManager gameboardManager;
private readonly IGameboardRepository gameboardRepository;
public SocketController(
ISocketTokenManager tokenManager,
IGameboardRepositoryManager gameboardManager)
ILogger<SocketController> logger,
ISocketTokenManager tokenManager,
IGameboardRepositoryManager gameboardManager,
IGameboardRepository gameboardRepository)
{
this.logger = logger;
this.tokenManager = tokenManager;
this.gameboardManager = gameboardManager;
this.gameboardRepository = gameboardRepository;
}
[Route("Token")]
[HttpGet("Token")]
public IActionResult GetToken()
{
var userName = HttpContext.User.Claims.First(c => c.Type == "preferred_username").Value;
@@ -33,7 +41,7 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
}
[AllowAnonymous]
[Route("GuestToken")]
[HttpGet("GuestToken")]
public async Task<IActionResult> GetGuestToken([FromQuery] GetGuestToken request)
{
if (request.ClientId == null)
@@ -44,7 +52,7 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
}
else
{
if (await gameboardManager.PlayerExists(request.ClientId))
if (await gameboardRepository.IsGuestUser(request.ClientId))
{
var token = tokenManager.GenerateToken(request.ClientId);
return new JsonResult(new GetGuestTokenResponse(request.ClientId, token));