wiring up new auth endpoint

This commit is contained in:
Michele 2021-05-28 23:14:40 +01:00
parent b6999cef0a
commit a13fb49942
17 changed files with 850 additions and 37 deletions

View File

@ -1,9 +1,10 @@
using System.Collections.Generic;
using MediatR;
using Sledgemapper.Shared.Entities;
namespace Sledgemapper.Api.Commands
{
public class GetCampaignsCommand : IRequest<List<Core.Entities.Campaign>>
public class GetCampaignsCommand : IRequest<List<Campaign>>
{
public string UserId { get; private set; }
public GetCampaignsCommand(string userId)

View File

@ -29,7 +29,7 @@ namespace Sledgemapper.Api.Controllers
}
[HttpGet]
public async Task<List<Core.Entities.Campaign>> Get()
public async Task<List<Campaign>> Get()
{
var result = await _mediator.Send(new GetCampaignsCommand(UserId));
return result;

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Entities;
@ -7,7 +8,7 @@ namespace Sledgemapper.Api.Core.Entities
[Index(nameof(CampaignName), nameof(OwnerId), IsUnique = true)]
public class Campaign
{
public int CampaignId { get; set; }
public Guid CampaignId { get; set; }
public string CampaignName { get; set; }
public string OwnerId { get; set; }

View File

@ -2,6 +2,7 @@ using MediatR;
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,7 +11,7 @@ using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class GetCampaignsCommandHandler : IRequestHandler<GetCampaignsCommand, List<Core.Entities.Campaign>>
public class GetCampaignsCommandHandler : IRequestHandler<GetCampaignsCommand, List<Campaign>>
{
private readonly IMediator _mediator;
private readonly SledgemapperDbContext _dbcontext;
@ -21,20 +22,22 @@ namespace Sledgemapper.Api.Handlers
_dbcontext = dbcontext;
}
public async Task<List<Core.Entities.Campaign>> Handle(GetCampaignsCommand command, CancellationToken cancellationToken)
public async Task<List<Campaign>> Handle(GetCampaignsCommand command, CancellationToken cancellationToken)
{
try
{
var user = await _dbcontext.Users.FindAsync(command.UserId);
_dbcontext.Attach(user);
var campaigns = _dbcontext.Campaigns.Include(c=>c.InvitedUsers).Include(c=>c.Owner).Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user));
var campaigns = _dbcontext.Campaigns.Include(c => c.InvitedUsers).Include(c => c.Owner).Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user));
return campaigns.ToList();
return campaigns.
Select(c => new Shared.Entities.Campaign { Id = c.CampaignId, Name = c.CampaignName, Maps = c.Maps.Select(m => new Shared.Entities.Map { SessionName = m.MapName }).ToList()})
.ToList();
}
catch (Exception ex)
{
}
return new List<Core.Entities.Campaign>();
return new List<Campaign>();
}
}
}

View File

@ -0,0 +1,503 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api.Migrations
{
[DbContext(typeof(SledgemapperDbContext))]
[Migration("20210528182730_ChangeCompanyId")]
partial class ChangeCompanyId
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.6");
modelBuilder.Entity("CampaignUser", b =>
{
b.Property<Guid>("CampaignsCampaignId")
.HasColumnType("TEXT");
b.Property<string>("InvitedUsersId")
.HasColumnType("TEXT");
b.HasKey("CampaignsCampaignId", "InvitedUsersId");
b.HasIndex("InvitedUsersId");
b.ToTable("CampaignUser");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.Property<Guid>("CampaignId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CampaignName")
.HasColumnType("TEXT");
b.Property<string>("OwnerId")
.HasColumnType("TEXT");
b.HasKey("CampaignId");
b.HasIndex("OwnerId");
b.HasIndex("CampaignName", "OwnerId")
.IsUnique();
b.ToTable("Campaigns");
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Map", b =>
{
b.Property<int>("MapId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CampaignId")
.HasColumnType("INTEGER");
b.Property<Guid?>("CampaignId1")
.HasColumnType("TEXT");
b.Property<string>("MapName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MapId");
b.HasIndex("CampaignId1");
b.ToTable("Maps");
});
modelBuilder.Entity("Sledgemapper.Api.Models.MapLog", b =>
{
b.Property<int>("MapLogId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Operation")
.IsRequired()
.HasMaxLength(1)
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("MapLogId");
b.ToTable("MapLogs");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Session", b =>
{
b.Property<int>("SessionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OwnerUserId")
.HasColumnType("INTEGER");
b.Property<string>("SessionName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("SessionId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Sledgemapper.Api.Models.SessionUser", b =>
{
b.Property<int>("SessionUserId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("SessionUserId");
b.ToTable("SessionUsers");
});
modelBuilder.Entity("Sledgemapper.Api.Models.Snapshot", b =>
{
b.Property<int>("SnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Object")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("SessionId")
.HasColumnType("INTEGER");
b.Property<double>("Timestamp")
.HasColumnType("REAL");
b.HasKey("SnapshotId");
b.ToTable("Snapshots");
});
modelBuilder.Entity("Sledgemapper.Api.Models.UserConnection", b =>
{
b.Property<int>("UserConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ConnectionId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("UserConnectionId");
b.ToTable("UserConnections");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.HasBaseType("Microsoft.AspNetCore.Identity.IdentityUser");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("Initials")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.ToTable("Users");
});
modelBuilder.Entity("CampaignUser", b =>
{
b.HasOne("Sledgemapper.Api.Core.Entities.Campaign", null)
.WithMany()
.HasForeignKey("CampaignsCampaignId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Sledgemapper.Entities.User", null)
.WithMany()
.HasForeignKey("InvitedUsersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.HasOne("Sledgemapper.Entities.User", "Owner")
.WithMany()
.HasForeignKey("OwnerId");
b.Navigation("Owner");
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Map", b =>
{
b.HasOne("Sledgemapper.Api.Core.Entities.Campaign", null)
.WithMany("Maps")
.HasForeignKey("CampaignId1");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithOne()
.HasForeignKey("Sledgemapper.Entities.User", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.Navigation("Maps");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,110 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Sledgemapper.Api.Migrations
{
public partial class ChangeCompanyId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Maps_Campaigns_CampaignId",
table: "Maps");
migrationBuilder.DropIndex(
name: "IX_Maps_CampaignId",
table: "Maps");
migrationBuilder.DropColumn(
name: "Username",
table: "Users");
migrationBuilder.AddColumn<Guid>(
name: "CampaignId1",
table: "Maps",
type: "TEXT",
nullable: true);
migrationBuilder.AlterColumn<Guid>(
name: "CampaignsCampaignId",
table: "CampaignUser",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER");
migrationBuilder.AlterColumn<Guid>(
name: "CampaignId",
table: "Campaigns",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER")
.OldAnnotation("Sqlite:Autoincrement", true);
migrationBuilder.CreateIndex(
name: "IX_Maps_CampaignId1",
table: "Maps",
column: "CampaignId1");
migrationBuilder.AddForeignKey(
name: "FK_Maps_Campaigns_CampaignId1",
table: "Maps",
column: "CampaignId1",
principalTable: "Campaigns",
principalColumn: "CampaignId",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Maps_Campaigns_CampaignId1",
table: "Maps");
migrationBuilder.DropIndex(
name: "IX_Maps_CampaignId1",
table: "Maps");
migrationBuilder.DropColumn(
name: "CampaignId1",
table: "Maps");
migrationBuilder.AddColumn<string>(
name: "Username",
table: "Users",
type: "TEXT",
nullable: true);
migrationBuilder.AlterColumn<int>(
name: "CampaignsCampaignId",
table: "CampaignUser",
type: "INTEGER",
nullable: false,
oldClrType: typeof(Guid),
oldType: "TEXT");
migrationBuilder.AlterColumn<int>(
name: "CampaignId",
table: "Campaigns",
type: "INTEGER",
nullable: false,
oldClrType: typeof(Guid),
oldType: "TEXT")
.Annotation("Sqlite:Autoincrement", true);
migrationBuilder.CreateIndex(
name: "IX_Maps_CampaignId",
table: "Maps",
column: "CampaignId");
migrationBuilder.AddForeignKey(
name: "FK_Maps_Campaigns_CampaignId",
table: "Maps",
column: "CampaignId",
principalTable: "Campaigns",
principalColumn: "CampaignId",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -14,12 +14,12 @@ namespace Sledgemapper.Api.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.3");
.HasAnnotation("ProductVersion", "5.0.6");
modelBuilder.Entity("CampaignUser", b =>
{
b.Property<int>("CampaignsCampaignId")
.HasColumnType("INTEGER");
b.Property<Guid>("CampaignsCampaignId")
.HasColumnType("TEXT");
b.Property<string>("InvitedUsersId")
.HasColumnType("TEXT");
@ -229,9 +229,9 @@ namespace Sledgemapper.Api.Migrations
modelBuilder.Entity("Sledgemapper.Api.Core.Entities.Campaign", b =>
{
b.Property<int>("CampaignId")
b.Property<Guid>("CampaignId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
.HasColumnType("TEXT");
b.Property<string>("CampaignName")
.HasColumnType("TEXT");
@ -258,13 +258,16 @@ namespace Sledgemapper.Api.Migrations
b.Property<int>("CampaignId")
.HasColumnType("INTEGER");
b.Property<Guid?>("CampaignId1")
.HasColumnType("TEXT");
b.Property<string>("MapName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MapId");
b.HasIndex("CampaignId");
b.HasIndex("CampaignId1");
b.ToTable("Maps");
});
@ -394,9 +397,6 @@ namespace Sledgemapper.Api.Migrations
b.Property<byte[]>("PasswordSalt")
.HasColumnType("BLOB");
b.Property<string>("Username")
.HasColumnType("TEXT");
b.ToTable("Users");
});
@ -479,9 +479,7 @@ namespace Sledgemapper.Api.Migrations
{
b.HasOne("Sledgemapper.Api.Core.Entities.Campaign", null)
.WithMany("Maps")
.HasForeignKey("CampaignId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("CampaignId1");
});
modelBuilder.Entity("Sledgemapper.Entities.User", b =>

View File

@ -1,4 +1,5 @@
using Sledgemapper.Shared.Entities;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Sledgemapper.Clients
@ -21,5 +22,7 @@ namespace Sledgemapper.Clients
Task RefreshPlayers();
Task NewLine(Line line);
Task Ping(Ping ping);
Task NewCampaign(string campaignName);
Task<List<Campaign>> GetCampaigns();
}
}

View File

@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using Sledgemapper.Shared.Entities;
public class Campaign
namespace Sledgemapper.Shared.Entities
{
public Guid Id {get;set;}
public string Name { get; set; }
public List<Map> Maps {get;set;}
public class Campaign
{
public Guid Id { get; set; }
public string Name { get; set; }
public List<Map> Maps { get; set; }
}
}

View File

@ -13,6 +13,9 @@ namespace Sledgemapper.Shared.Entities
[Required]
public string Username { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string Password { get; set; }
[Required]

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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>

View 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;
}
}

View 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();
}
}
}

View 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>