small tweaks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-25 21:03:11 +01:00
parent 633c97e0da
commit 94f71fc00f
4 changed files with 55 additions and 11 deletions

View File

@ -15,6 +15,10 @@ using Sledgemapper.Api.Models;
namespace Sledgemapper.Api.Controllers
{
// TODO
// introduce refresh token from https://github.com/mohamadlawand087/v8-refreshtokenswithJWT
// and https://dev.to/moe23/refresh-jwt-with-refresh-tokens-in-asp-net-core-5-rest-api-step-by-step-3en5
[Route("[controller]")] // api/authmanagement
[ApiController]
public class AuthManagementController : ControllerBase
@ -117,6 +121,7 @@ namespace Sledgemapper.Api.Controllers
{
Result = true,
Token = jwtToken,
Username = existingUser.Email,
Initials = existingUser.Initials,
Id = existingUser.Id

View File

@ -327,18 +327,30 @@ namespace Sledgemapper
return result;
}
public async Task ResetSignalrConnection()
{
try
{
await Connection.StopAsync();
}
catch (Exception ex)
{
}
await Connection.StartAsync();
}
public void CheckLogin()
{
var data = Program.helper.LoadUnencryptedTokenCache();
if (data != null && data.Any())
{
try
{
_authenticateResponse = JsonSerializer.Deserialize<AuthenticateResponse>(Encoding.UTF8.GetString(data));
Messenger.Publish(new LoginSuccesfulMessage(this) { UserName = _authenticateResponse.Username, Initials = _authenticateResponse.Initials });
}
catch
{ }
}
}
}

View File

@ -3,6 +3,7 @@ using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;
using Sentry;
namespace Sledgemapper
{
@ -41,7 +42,23 @@ namespace Sledgemapper
helper = MsalCacheHelper.CreateAsync(storageProperties).Result;
using (Sentry.SentrySdk.Init("https://973ac1606651454ba7a19f642d0a9bc1@glitchtip.michelescandura.com/1"))
using (Sentry.SentrySdk.Init(o =>
{
o.Dsn = "https://973ac1606651454ba7a19f642d0a9bc1@glitchtip.michelescandura.com/1";
o.MaxBreadcrumbs = 50;
o.Debug = true;
o.StackTraceMode = StackTraceMode.Enhanced;
o.AttachStacktrace = true;
o.Release = "1.0.0-alpha.3";
#if DEBUG
o.Environment = "dev";
#else
o.Environment="production";
#endif
o.ServerName = Settings.Instance.MachineName;
}))
using (var game = new Sledgemapper())
{
Sentry.SentrySdk.CaptureEvent(new Sentry.SentryEvent() { Message = "App starting" });

View File

@ -222,7 +222,7 @@ namespace Sledgemapper.UI
_windowEditor.ShowModal(Desktop);
}
private void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
private async void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
{
//MenuConnectNew.Enabled = true;
//MenuConnectJoin.Enabled = true;
@ -235,6 +235,7 @@ namespace Sledgemapper.UI
MenuCampaignPlayers.Enabled = false;
lblCampaign.Text = "n/a";
lblMap.Text = "n/a";
//await CommunicationManager.ResetSignalrConnection();
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
lblUsername.Text = $"{obj.Initials}";
@ -267,6 +268,15 @@ namespace Sledgemapper.UI
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
{
try
{
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
await CommunicationManager.Connection.StartAsync();
UpdateConnectionState(CommunicationManager.Connection);
}