Merge branch 'refactoring' of https://git.michelescandura.com/michele/Map into refactoring
This commit is contained in:
commit
ea9cc32534
15 changed files with 135 additions and 44 deletions
15
Sledgemapper.Api/Commands/NewSessionCommand.cs
Normal file
15
Sledgemapper.Api/Commands/NewSessionCommand.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using MediatR;
|
||||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public class NewSessionCommand : IRequest<bool>
|
||||
{
|
||||
public string SessionName { get; set; }
|
||||
public int UserId { get; }
|
||||
public NewSessionCommand(string sessionName, int userId)
|
||||
{
|
||||
SessionName = sessionName;
|
||||
UserId = userId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Handlers;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -15,6 +16,15 @@ namespace Sledgemapper.Api.Controllers
|
|||
|
||||
public SessionController(IMediator mediator) { _mediator = mediator; }
|
||||
|
||||
[HttpPost]
|
||||
public async Task Post(string sessionName)
|
||||
{
|
||||
var userId = int.Parse(HttpContext.User.Identity.Name);
|
||||
|
||||
var result = await _mediator.Send(new NewSessionCommand(sessionName, userId));
|
||||
|
||||
}
|
||||
|
||||
[HttpPost("tile")]
|
||||
public async Task Post(string sessionName, [FromBody]Tile tile)
|
||||
{
|
||||
|
|
32
Sledgemapper.Api/Handlers/StartNewSessionHandler.cs
Normal file
32
Sledgemapper.Api/Handlers/StartNewSessionHandler.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using MediatR;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Data;
|
||||
using Sledgemapper.Api.Models;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class StartNewSessionHandler : IRequestHandler<NewSessionCommand, bool>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly MyDbContext _dbcontext;
|
||||
|
||||
public StartNewSessionHandler(IMediator mediator, MyDbContext dbcontext)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_dbcontext = dbcontext;
|
||||
}
|
||||
|
||||
public async Task<bool> Handle(NewSessionCommand notification, CancellationToken cancellationToken)
|
||||
{
|
||||
// _dbcontext.MapLogs.Add(new Session
|
||||
// {
|
||||
// SessionName = notification.SessionName,
|
||||
// OwnerUserId = notification.UserId
|
||||
// });
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,10 +15,13 @@ using Microsoft.AspNetCore.Authorization;
|
|||
|
||||
namespace SignalRChat.Hubs
|
||||
{
|
||||
|
||||
|
||||
[Authorize]
|
||||
public class SledgemapperHub : Hub<ISledgemapperClient>
|
||||
{
|
||||
public SledgemapperHub() {
|
||||
public SledgemapperHub()
|
||||
{
|
||||
|
||||
}
|
||||
private static Dictionary<string, Session> _sessions = new Dictionary<string, Session>();
|
||||
|
@ -113,6 +116,10 @@ namespace SignalRChat.Hubs
|
|||
|
||||
public async Task<Session> NewSession(string sessionName, string initials)
|
||||
{
|
||||
|
||||
var userId = int.Parse(Context.User.Identity.Name);
|
||||
|
||||
// var user = this.Context.GetHttpContext().;
|
||||
var session = new Session();
|
||||
session.Colors = new List<string>(Colors);
|
||||
session.Colors.Shuffle();
|
||||
|
|
17
Sledgemapper.Api/Models/Session.cs
Normal file
17
Sledgemapper.Api/Models/Session.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Sledgemapper.Api.Models
|
||||
{
|
||||
public class Session
|
||||
{
|
||||
[Key]
|
||||
public int SessionId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string SessionName{get;set;}
|
||||
|
||||
[Required]
|
||||
public int OwnerUserId { get; set; }
|
||||
}
|
||||
}
|
Binary file not shown.
8
Sledgemapper.Api/Notifications/NewSessionNotification.cs
Normal file
8
Sledgemapper.Api/Notifications/NewSessionNotification.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class NewSessionNotification : BaseNotification
|
||||
{
|
||||
public int UserId { get; }
|
||||
public NewSessionNotification(string sessionName, int userId) : base(sessionName) => UserId = userId;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|||
using System.Text;
|
||||
using AutoMapper;
|
||||
using Sledgemapper.Services;
|
||||
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace SignalRChat
|
||||
{
|
||||
|
@ -79,6 +79,8 @@ namespace SignalRChat
|
|||
// return unauthorized if user no longer exists
|
||||
context.Fail("Unauthorized");
|
||||
}
|
||||
context.HttpContext.User.Claims.Append(new Claim(ClaimTypes.Name, user.Username));
|
||||
context.HttpContext.User.Claims.Append(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
|
|
Binary file not shown.
|
@ -17,6 +17,7 @@ namespace Sledgemapper
|
|||
public HubConnection Connection { get; private set; }
|
||||
public Session SessionData;
|
||||
private ChannelsQueue Queue = new ChannelsQueue();
|
||||
private AuthenticateResponse _authenticateResponse;
|
||||
|
||||
public CommunicationManager(Session sessionData)
|
||||
{
|
||||
|
@ -24,7 +25,10 @@ namespace Sledgemapper
|
|||
Connection = new HubConnectionBuilder()
|
||||
.WithAutomaticReconnect()
|
||||
|
||||
.WithUrl("http://localhost:5000/SledgemapperHub")
|
||||
.WithUrl("http://localhost:5000/SledgemapperHub", options =>
|
||||
{
|
||||
options.AccessTokenProvider = () => Task.FromResult(_authenticateResponse.Token);
|
||||
})
|
||||
|
||||
// .WithUrl("http://hub.michelescandura.com:5000/SledgemapperHub")
|
||||
.Build();
|
||||
|
@ -110,6 +114,18 @@ namespace Sledgemapper
|
|||
});
|
||||
}
|
||||
|
||||
public async Task<bool> Register(RegisterModel registerModel)
|
||||
{
|
||||
var result = await Api.Register(registerModel);
|
||||
return result.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<AuthenticateResponse> Login(AuthenticateModel authenticateModel)
|
||||
{
|
||||
_authenticateResponse = await Api.Authenticate(authenticateModel);
|
||||
return _authenticateResponse;
|
||||
}
|
||||
|
||||
private async Task Execute(Func<Task> call)
|
||||
{
|
||||
await Policy
|
||||
|
|
|
@ -3,6 +3,7 @@ using Sledgemapper.Shared.Entities;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -27,5 +28,11 @@ namespace Sledgemapper
|
|||
|
||||
[Delete("/session/{sessionName}/overlay")]
|
||||
Task DeleteOverlay([Body] Overlay overlay, string sessionName);
|
||||
|
||||
[Post("/users/register")]
|
||||
Task<HttpResponseMessage> Register([Body] RegisterModel registerModel);
|
||||
|
||||
[Post("/users/authenticate")]
|
||||
Task<AuthenticateResponse> Authenticate([Body] AuthenticateModel registerModel);
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -243,7 +243,8 @@ namespace Sledgemapper
|
|||
{
|
||||
return;
|
||||
}
|
||||
GraphicsDevice.Clear(new Color(24,118,157));
|
||||
//GraphicsDevice.Clear(new Color(24,118,157));
|
||||
GraphicsDevice.Clear(Color.LightGray);
|
||||
|
||||
var visibleTilesX = GraphicsDevice.Viewport.Width / _state._tileSize + 1;
|
||||
var visibleTilesY = GraphicsDevice.Viewport.Height / _state._tileSize + 1;
|
||||
|
@ -518,20 +519,8 @@ namespace Sledgemapper
|
|||
var successful = false;
|
||||
try
|
||||
{
|
||||
var httpClientHandler = new HttpClientHandler();
|
||||
|
||||
#if DEBUG
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback =
|
||||
(message, certificate, chain, sslPolicyErrors) => true;
|
||||
#endif
|
||||
|
||||
var identiyApi = RestService.For<IIdentityApi>(
|
||||
new HttpClient(httpClientHandler)
|
||||
{
|
||||
BaseAddress = new Uri("http://localhost:4000")
|
||||
});
|
||||
|
||||
_authResponse = await identiyApi.Authenticate(new AuthenticateModel
|
||||
_authResponse = await _communicationManager.Login(new AuthenticateModel
|
||||
{
|
||||
Username = localContent.TxtEmail.Text,
|
||||
Password = localContent.TxtPassword.Text
|
||||
|
@ -577,19 +566,7 @@ namespace Sledgemapper
|
|||
var successful = false;
|
||||
try
|
||||
{
|
||||
var httpClientHandler = new HttpClientHandler();
|
||||
|
||||
#if DEBUG
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback =
|
||||
(message, certificate, chain, sslPolicyErrors) => true;
|
||||
#endif
|
||||
|
||||
var identiyApi = RestService.For<IIdentityApi>(
|
||||
new HttpClient(httpClientHandler)
|
||||
{
|
||||
BaseAddress = new Uri("http://localhost:4000")
|
||||
});
|
||||
var result = await identiyApi.Register(new RegisterModel
|
||||
var result = await _communicationManager.Register(new RegisterModel
|
||||
{
|
||||
Username = localContent.TxtEmail.Text,
|
||||
Password = localContent.TxtPassword.Text,
|
||||
|
@ -597,9 +574,9 @@ namespace Sledgemapper
|
|||
LastName = localContent.TxtLastname.Text,
|
||||
Initials = localContent.TxtInitials.Text
|
||||
});
|
||||
if (result.IsSuccessStatusCode)
|
||||
if (result)
|
||||
{
|
||||
_authResponse = await identiyApi.Authenticate(new AuthenticateModel
|
||||
_authResponse = await _communicationManager.Login(new AuthenticateModel
|
||||
{
|
||||
Username = localContent.TxtEmail.Text,
|
||||
Password = localContent.TxtPassword.Text
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by MyraPad at 10/11/2020 15:49:08 */
|
||||
/* Generated by MyraPad at 11/11/2020 09:47:53 */
|
||||
using Myra.Graphics2D;
|
||||
using Myra.Graphics2D.TextureAtlases;
|
||||
using Myra.Graphics2D.UI;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue