wiring up new auth endpoint
This commit is contained in:
parent
b6999cef0a
commit
a13fb49942
17 changed files with 850 additions and 37 deletions
|
@ -167,7 +167,7 @@ namespace Sledgemapper
|
|||
return Task.FromResult(_authenticateResponse.Token);
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> Register(RegisterModel registerModel)
|
||||
public async Task<IMapApi.AuthResult> Register(RegisterModel registerModel)
|
||||
{
|
||||
var result = await Api.Register(registerModel).ConfigureAwait(false);
|
||||
return result;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Refit;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -42,12 +43,19 @@ namespace Sledgemapper
|
|||
Task DeleteNote([Body] Note overlay, string sessionName);
|
||||
|
||||
|
||||
[Headers("Authorization")]
|
||||
[Post("/users/register")]
|
||||
Task<HttpResponseMessage> Register([Body] RegisterModel registerModel);
|
||||
public class AuthResult
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public bool Result { get; set; }
|
||||
public List<string> Errors { get; set; }
|
||||
}
|
||||
|
||||
[Headers("Authorization")]
|
||||
[Post("/users/authenticate")]
|
||||
[Post("/authmanagement/register")]
|
||||
Task<AuthResult> Register([Body] RegisterModel registerModel);
|
||||
|
||||
[Headers("Authorization")]
|
||||
[Post("/authmanagement/authenticate")]
|
||||
Task<AuthenticateResponse> Authenticate([Body] AuthenticateModel registerModel);
|
||||
|
||||
[Post("/session/{sessionName}/room")]
|
||||
|
@ -55,5 +63,8 @@ namespace Sledgemapper
|
|||
|
||||
[Post("/session/{sessionName}/line")]
|
||||
Task NewLine(Line line, string sessionName);
|
||||
|
||||
[Post("/campaign/{campaignName}")]
|
||||
Task NewCampaign(string campaignName);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using Exceptionless;
|
||||
using Exceptionless;
|
||||
using Exceptionless.Models;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
@ -211,6 +211,8 @@ namespace Sledgemapper
|
|||
_mainWidget.MenuViewCenterOnSelection.Selected += OnMenuViewCenterOnSelectionSelected;
|
||||
_mainWidget.MenuViewShowCellNUmbers.Selected += OnMenuViewShowCellNUmbersSelected;
|
||||
_mainWidget.MenuViewShowNotes.Selected += OnMenuViewNotesSelected;
|
||||
_mainWidget.MenuCampaingNew.Selected += OnMenuCampaignNew;
|
||||
|
||||
_mainWidget.MenuConnectNew.Enabled = false;
|
||||
_mainWidget.MenuConnectJoin.Enabled = false;
|
||||
_mainWidget.MenuConnectSync.Enabled = false;
|
||||
|
@ -219,6 +221,7 @@ namespace Sledgemapper
|
|||
_mainWidget.BtnToolbarRoom.Click += OnBtnToolbarRoomClicked;
|
||||
_mainWidget.BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
|
||||
|
||||
|
||||
_wallsContent = Content.LoadContentFolder<Texture2D>("walls");
|
||||
|
||||
_spriteSheet = new SpriteSheet();
|
||||
|
@ -298,6 +301,27 @@ namespace Sledgemapper
|
|||
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
|
||||
}
|
||||
|
||||
private void OnMenuCampaignNew(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = "New campaign"
|
||||
};
|
||||
|
||||
var content = new CampaignWindow();
|
||||
//content.BtnNewCampaign.Text = "N";
|
||||
content.BtnNewCampaign.Click += OnButtonNewCampaignClicked;
|
||||
window.Content = content;
|
||||
|
||||
window.ShowModal(_desktop);
|
||||
content.TxtCampaign.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
|
||||
{
|
||||
var propertyGrid = new PropertyGrid
|
||||
|
@ -1900,6 +1924,64 @@ namespace Sledgemapper
|
|||
}
|
||||
}
|
||||
|
||||
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
|
||||
{
|
||||
Container container = ((TextButton)sender).Parent;
|
||||
while (!(container is Window))
|
||||
{
|
||||
container = container.Parent;
|
||||
}
|
||||
var localWindow = (Window)container;
|
||||
var localContent = localWindow.Content as CampaignWindow;
|
||||
var isValid = ValidateTextbox(localContent.TxtCampaign);
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_communicationManager.Connection.State != HubConnectionState.Connected)
|
||||
{
|
||||
_mainWidget.lblConnectionStatus.Text = "Connecting";
|
||||
await _communicationManager.Connection.StartAsync();
|
||||
UpdateConnectionState(_communicationManager.Connection);
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
try
|
||||
{
|
||||
await _communicationManager.Api.NewCampaign(localContent.TxtCampaign.Text);
|
||||
|
||||
//if (result)
|
||||
//{
|
||||
// _sessionData.SessionName = localContent.TxtSession.Text;
|
||||
// _sessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||
// _sessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||
// _sessionData.MapEntityAdded += OnMapEntityAdded;
|
||||
// _sessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||
//}
|
||||
//successful = result;
|
||||
//var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text);
|
||||
//_sessionData.SessionId = result2.SessionId;
|
||||
//_sessionData.SessionName = localContent.TxtSession.Text;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionlessClient.Default.SubmitException(ex);
|
||||
}
|
||||
|
||||
if (successful)
|
||||
{
|
||||
//_sessionData.SessionName = localContent.TxtSession.Text;
|
||||
//_communicationManager.SessionData.Map = _sessionData.Map;
|
||||
//_communicationManager.SessionData.Overlays = _sessionData.Overlays;
|
||||
//_communicationManager.SessionData.Walls = _sessionData.Walls;
|
||||
//_mainWidget.lblSessionName.Text = _sessionData.SessionName;
|
||||
//_mainWidget.MenuConnectSync.Enabled = true;
|
||||
//_mainWidget.MenuConnectUpload.Enabled = true;
|
||||
localWindow.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
|
||||
{
|
||||
Container container = ((TextButton)sender).Parent;
|
||||
|
@ -2124,12 +2206,13 @@ namespace Sledgemapper
|
|||
var result = await _communicationManager.Register(new RegisterModel
|
||||
{
|
||||
Username = localContent.TxtEmail.Text,
|
||||
Email = localContent.TxtEmail.Text,
|
||||
Password = localContent.TxtPassword.Text,
|
||||
FirstName = localContent.TxtFirstname.Text,
|
||||
LastName = localContent.TxtLastname.Text,
|
||||
Initials = localContent.TxtInitials.Text
|
||||
});
|
||||
if (result.IsSuccessStatusCode)
|
||||
if (result.Result)
|
||||
{
|
||||
_authResponse = await _communicationManager.Login(new AuthenticateModel
|
||||
{
|
||||
|
@ -2140,7 +2223,7 @@ namespace Sledgemapper
|
|||
}
|
||||
else
|
||||
{
|
||||
localContent.LblLoginError.Text = result.ReasonPhrase;
|
||||
localContent.LblLoginError.Text = result.Errors.FirstOrDefault();
|
||||
localContent.LblLoginError.Visible = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,13 +48,13 @@
|
|||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
||||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client">
|
||||
<Version>5.0.4</Version>
|
||||
<Version>5.0.6</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Myra" Version="1.2.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="polly" Version="7.2.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="polly" Version="7.2.2" />
|
||||
<PackageReference Include="polly.extensions.http" Version="3.0.0" />
|
||||
<PackageReference Include="Refit.HttpClientFactory" Version="6.0.24" />
|
||||
<PackageReference Include="Refit.HttpClientFactory" Version="6.0.38" />
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
67
Sledgemapper/UI/CampaignWindow.Generated.cs
Normal file
67
Sledgemapper/UI/CampaignWindow.Generated.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* Generated by MyraPad at 28/05/2021 22:36:14 */
|
||||
using Myra;
|
||||
using Myra.Graphics2D;
|
||||
using Myra.Graphics2D.TextureAtlases;
|
||||
using Myra.Graphics2D.UI;
|
||||
using Myra.Graphics2D.Brushes;
|
||||
using Myra.Graphics2D.UI.Properties;
|
||||
|
||||
#if MONOGAME || FNA
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
#elif STRIDE
|
||||
using Stride.Core.Mathematics;
|
||||
#else
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
#endif
|
||||
|
||||
namespace Sledgemapper.UI
|
||||
{
|
||||
partial class CampaignWindow: VerticalStackPanel
|
||||
{
|
||||
private void BuildUI()
|
||||
{
|
||||
var label1 = new Label();
|
||||
label1.Text = "Campaign";
|
||||
|
||||
TxtCampaign = new TextBox();
|
||||
TxtCampaign.GridColumn = 1;
|
||||
TxtCampaign.Id = "TxtCampaign";
|
||||
|
||||
var grid1 = new Grid();
|
||||
grid1.ColumnSpacing = 25;
|
||||
grid1.RowSpacing = 10;
|
||||
grid1.ColumnsProportions.Add(new Proportion
|
||||
{
|
||||
Type = Myra.Graphics2D.UI.ProportionType.Pixels,
|
||||
Value = 60,
|
||||
});
|
||||
grid1.ColumnsProportions.Add(new Proportion
|
||||
{
|
||||
Type = Myra.Graphics2D.UI.ProportionType.Fill,
|
||||
});
|
||||
grid1.Widgets.Add(label1);
|
||||
grid1.Widgets.Add(TxtCampaign);
|
||||
|
||||
BtnNewCampaign = new TextButton();
|
||||
BtnNewCampaign.Text = "New";
|
||||
BtnNewCampaign.Padding = new Thickness(10, 5);
|
||||
BtnNewCampaign.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
|
||||
BtnNewCampaign.Id = "BtnNewCampaign";
|
||||
|
||||
|
||||
Spacing = 16;
|
||||
HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
|
||||
VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
|
||||
Width = 300;
|
||||
Padding = new Thickness(10);
|
||||
Widgets.Add(grid1);
|
||||
Widgets.Add(BtnNewCampaign);
|
||||
}
|
||||
|
||||
|
||||
public TextBox TxtCampaign;
|
||||
public TextButton BtnNewCampaign;
|
||||
}
|
||||
}
|
11
Sledgemapper/UI/CampaignWindow.cs
Normal file
11
Sledgemapper/UI/CampaignWindow.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
/* Generated by MyraPad at 28/05/2021 22:36:14 */
|
||||
namespace Sledgemapper.UI
|
||||
{
|
||||
public partial class CampaignWindow
|
||||
{
|
||||
public CampaignWindow()
|
||||
{
|
||||
BuildUI();
|
||||
}
|
||||
}
|
||||
}
|
17
Sledgemapper/UI/campaignWindow.xmmp
Normal file
17
Sledgemapper/UI/campaignWindow.xmmp
Normal file
|
@ -0,0 +1,17 @@
|
|||
<Project>
|
||||
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="CampaignWindow" OutputPath="C:\dev\Map\Sledgemapper\UI" />
|
||||
<VerticalStackPanel Spacing="16" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Padding="10">
|
||||
|
||||
<Grid ColumnSpacing="25" RowSpacing="10">
|
||||
<Grid.ColumnsProportions>
|
||||
<Proportion Type="Pixels" Value="60" />
|
||||
<Proportion Type="Fill" />
|
||||
</Grid.ColumnsProportions>
|
||||
<Label Text="Campaign" />
|
||||
|
||||
<TextBox GridColumn="1" Id="TxtCampaign" />
|
||||
|
||||
</Grid>
|
||||
<TextButton Text="New" Padding="10, 5" HorizontalAlignment="Center" Id="BtnNewCampaign" />
|
||||
</VerticalStackPanel>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue