From 194f3cbffaa650d5fc8a6f81d9e5489a84ef5d69 Mon Sep 17 00:00:00 2001 From: Michele Scandura Date: Tue, 10 Nov 2020 12:14:21 +0000 Subject: [PATCH] login flow --- Identity/Controllers/UsersController.cs | 1 + Identity/Entities/User.cs | 1 + Identity/LocalDatabase.db | Bin 20480 -> 20480 bytes .../20200102102942_InitialCreate.Designer.cs | 3 + .../20200102102942_InitialCreate.cs | 1 + .../SqliteDataContextModelSnapshot.cs | 3 + Identity/Models/Users/RegisterModel.cs | 3 + Identity/Models/Users/UserModel.cs | 1 + Sledgemapper.Api/Data/MyDbContext.cs | 40 +- .../Entities/AuthenticateModel.cs | 13 + .../Entities/AuthenticateResponse.cs | 11 + Sledgemapper.Shared/Entities/RegisterModel.cs | 21 + Sledgemapper.Shared/Entities/Tile.cs | 1 + Sledgemapper/IIdentityApi.cs | 20 + Sledgemapper/MyDatabase.db | Bin 143360 -> 143360 bytes Sledgemapper/Sledgemapper.cs | 383 ++++++++++++------ .../UI/LoginRegisterWindow.Generated.cs | 153 +++++++ Sledgemapper/UI/LoginRegisterWindow.cs | 11 + Sledgemapper/UI/SessionWindow.Generated.cs | 62 +++ Sledgemapper/UI/SessionWindow.cs | 11 + Sledgemapper/UI/loginwindow.xml | 27 ++ Sledgemapper/UI/sessionwindow.xml | 17 + 22 files changed, 642 insertions(+), 141 deletions(-) create mode 100644 Sledgemapper.Shared/Entities/AuthenticateModel.cs create mode 100644 Sledgemapper.Shared/Entities/AuthenticateResponse.cs create mode 100644 Sledgemapper.Shared/Entities/RegisterModel.cs create mode 100644 Sledgemapper/IIdentityApi.cs create mode 100644 Sledgemapper/UI/LoginRegisterWindow.Generated.cs create mode 100644 Sledgemapper/UI/LoginRegisterWindow.cs create mode 100644 Sledgemapper/UI/SessionWindow.Generated.cs create mode 100644 Sledgemapper/UI/SessionWindow.cs create mode 100644 Sledgemapper/UI/loginwindow.xml create mode 100644 Sledgemapper/UI/sessionwindow.xml diff --git a/Identity/Controllers/UsersController.cs b/Identity/Controllers/UsersController.cs index 7d6a461..69c459b 100644 --- a/Identity/Controllers/UsersController.cs +++ b/Identity/Controllers/UsersController.cs @@ -64,6 +64,7 @@ namespace WebApi.Controllers Username = user.Username, FirstName = user.FirstName, LastName = user.LastName, + Initials = user.Initials, Token = tokenString }); } diff --git a/Identity/Entities/User.cs b/Identity/Entities/User.cs index d948a87..fdba014 100644 --- a/Identity/Entities/User.cs +++ b/Identity/Entities/User.cs @@ -6,6 +6,7 @@ namespace WebApi.Entities public string FirstName { get; set; } public string LastName { get; set; } public string Username { get; set; } + public string Initials { get; set; } public byte[] PasswordHash { get; set; } public byte[] PasswordSalt { get; set; } } diff --git a/Identity/LocalDatabase.db b/Identity/LocalDatabase.db index 2023e65ad73159c69fc675e741fca6c6fd4584df..eb7cd4660debd7914c1286d69e799e0b23b38723 100644 GIT binary patch delta 339 zcmZozz}T>WaY7bXI0N4${_4*F3#AZJ^38(X%5f4%#zH+ zoZ`)Ge07R!jQk=D{34qL1-SU@8#5WX7^G!21si#qcycq7Gg5O>i<1-cQc8;wpTlH@UVnq*{R%;g`bpHY~gQPyqE3$*SrGuzYYTRe|B;5 zd9M-i{yc5bjD*9z-iC`e{$`WVO|P1zdy&KNh{!2-cZFSD%creu&0Suv@7cY5dYkJO zgXb5DFFy|qxKZGtm!-_LpyR?H78#c-=XWj%Ouwp~Z1?8p z#>0mbo-W(7&@B2T delta 73 zcmZozz}T>WaY7bX5d+^P{("LastName") .HasColumnType("TEXT"); + b.Property("Initials") + .HasColumnType("TEXT"); + b.Property("PasswordHash") .HasColumnType("BLOB"); diff --git a/Identity/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs b/Identity/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs index 7562f4f..100616c 100644 --- a/Identity/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs +++ b/Identity/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs @@ -16,6 +16,7 @@ namespace WebApi.Migrations.SqliteMigrations FirstName = table.Column(nullable: true), LastName = table.Column(nullable: true), Username = table.Column(nullable: true), + Initials = table.Column(nullable: true), PasswordHash = table.Column(nullable: true), PasswordSalt = table.Column(nullable: true) }, diff --git a/Identity/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs b/Identity/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs index 84c2760..c65dc4c 100644 --- a/Identity/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs +++ b/Identity/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs @@ -28,6 +28,9 @@ namespace WebApi.Migrations.SqliteMigrations b.Property("LastName") .HasColumnType("TEXT"); + b.Property("Initials") + .HasColumnType("TEXT"); + b.Property("PasswordHash") .HasColumnType("BLOB"); diff --git a/Identity/Models/Users/RegisterModel.cs b/Identity/Models/Users/RegisterModel.cs index 92bdc1f..91930a5 100644 --- a/Identity/Models/Users/RegisterModel.cs +++ b/Identity/Models/Users/RegisterModel.cs @@ -15,5 +15,8 @@ namespace WebApi.Models.Users [Required] public string Password { get; set; } + + [Required] + public string Initials { get; set; } } } \ No newline at end of file diff --git a/Identity/Models/Users/UserModel.cs b/Identity/Models/Users/UserModel.cs index 9c61d04..c0e054f 100644 --- a/Identity/Models/Users/UserModel.cs +++ b/Identity/Models/Users/UserModel.cs @@ -6,5 +6,6 @@ namespace WebApi.Models.Users public string FirstName { get; set; } public string LastName { get; set; } public string Username { get; set; } + public string Initials { get; set; } } } \ No newline at end of file diff --git a/Sledgemapper.Api/Data/MyDbContext.cs b/Sledgemapper.Api/Data/MyDbContext.cs index 1fa29b3..7040458 100644 --- a/Sledgemapper.Api/Data/MyDbContext.cs +++ b/Sledgemapper.Api/Data/MyDbContext.cs @@ -12,42 +12,42 @@ namespace Sledgemapper.Api.Data context.Database.EnsureCreated(); } } - - - public class MyDbContext : DbContext - { - public DbSet MapLogs { get; set; } - public MyDbContext(DbContextOptions options):base(options) - { - ChangeTracker.QueryTrackingBehavior=QueryTrackingBehavior.NoTracking; - } + + public class MyDbContext : DbContext + { + public DbSet MapLogs { get; set; } + + public MyDbContext(DbContextOptions options) : base(options) + { + + } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { + { // optionsBuilder. // options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName); // optionsBuilder.UseSqlite("Filename=SledgemapperDatabase.db", options => // { // options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName); // }); - optionsBuilder.UseSqlite("Filename=MyDatabase.db"); + optionsBuilder.UseSqlite("Filename=MyDatabase.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); base.OnConfiguring(optionsBuilder); - } + } protected override void OnModelCreating(ModelBuilder modelBuilder) - { - // Map table names - modelBuilder.Entity().ToTable("MapLog", "dbo"); - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.MapLogId); + { + // Map table names + modelBuilder.Entity().ToTable("MapLog", "dbo"); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.MapLogId); //entity.HasIndex(e => {e.SessionName, e.Timestamp}); }); base.OnModelCreating(modelBuilder); - } - } + } + } } \ No newline at end of file diff --git a/Sledgemapper.Shared/Entities/AuthenticateModel.cs b/Sledgemapper.Shared/Entities/AuthenticateModel.cs new file mode 100644 index 0000000..61c8d20 --- /dev/null +++ b/Sledgemapper.Shared/Entities/AuthenticateModel.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace Sledgemapper.Shared.Entities +{ + public class AuthenticateModel + { + [Required] + public string Username { get; set; } + + [Required] + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/Sledgemapper.Shared/Entities/AuthenticateResponse.cs b/Sledgemapper.Shared/Entities/AuthenticateResponse.cs new file mode 100644 index 0000000..9390fbf --- /dev/null +++ b/Sledgemapper.Shared/Entities/AuthenticateResponse.cs @@ -0,0 +1,11 @@ +namespace Sledgemapper.Shared.Entities +{ + public class AuthenticateResponse + { + public string Id { get; set; } + public string Username { get; set; } + public string Firstname { get; set; } + public string LastName { get; set; } + public string Token { get; set; } + } +} \ No newline at end of file diff --git a/Sledgemapper.Shared/Entities/RegisterModel.cs b/Sledgemapper.Shared/Entities/RegisterModel.cs new file mode 100644 index 0000000..d739ba1 --- /dev/null +++ b/Sledgemapper.Shared/Entities/RegisterModel.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; + +namespace Sledgemapper.Shared.Entities +{ + public class RegisterModel + { + [Required] + public string FirstName { get; set; } + + [Required] + public string LastName { get; set; } + + [Required] + public string Username { get; set; } + + [Required] + public string Password { get; set; } + [Required] + public string Initials { get; set; } + } +} \ No newline at end of file diff --git a/Sledgemapper.Shared/Entities/Tile.cs b/Sledgemapper.Shared/Entities/Tile.cs index 5c43114..932da5a 100644 --- a/Sledgemapper.Shared/Entities/Tile.cs +++ b/Sledgemapper.Shared/Entities/Tile.cs @@ -10,6 +10,7 @@ { return $"{X}_{Y}"; } + public double Timestamp {get;set;} } public class Tile :BaseMapEntity diff --git a/Sledgemapper/IIdentityApi.cs b/Sledgemapper/IIdentityApi.cs new file mode 100644 index 0000000..57fc5ff --- /dev/null +++ b/Sledgemapper/IIdentityApi.cs @@ -0,0 +1,20 @@ +using Refit; +using Sledgemapper.Shared.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace Sledgemapper +{ + public interface IIdentityApi + { + [Post("/users/register")] + Task Register([Body] RegisterModel registerModel); + + [Post("/users/authenticate")] + Task Authenticate([Body] AuthenticateModel registerModel); + } +} \ No newline at end of file diff --git a/Sledgemapper/MyDatabase.db b/Sledgemapper/MyDatabase.db index ca53fb411f671093e951a013ed4a1ab9964f4deb..cc490d7759c29edf31849985a5c7d2f075260049 100644 GIT binary patch delta 1208 zcmZp8z|ru4W5a)a#)jKFq|h&9 zx*;E<$n*nIj3R1=STt;s^X`d7)(}2Dz@AZba+rvSF&5=&G2T5fD9Rxr2n>fvB`ZVY z$^IhJSfWT?d8>C%G?KpQV6S3xkl20io+vbxSiLG7>D?2Fq!7ugqS&0k^VYj30!ck6 zmB>t9E6Jye#TjzH&wKZTBdLZZ6{G1Fg&Bo$YWp_FyC)2bHePTsvhwZ;MbZXJ zGGMo1RsHRdcTWhiYG7)>t@=~0cTX^~YN)^YvE&fBciX&sf{+x$ybX6hR$Xs6yn6z% w=z<3pKb8oQd(h(D6M&=(=4q^o?;iH<@kdq+^)tUHW-67tdwBaYO{OR|00h%@bpQYW delta 37 tcmZp8z|ru4W5a)aM!zP5Z3c`iADAULmrZ9^U^3iTn8&$&nI=;d8vqXD495Tf diff --git a/Sledgemapper/Sledgemapper.cs b/Sledgemapper/Sledgemapper.cs index 7821992..431c07d 100644 --- a/Sledgemapper/Sledgemapper.cs +++ b/Sledgemapper/Sledgemapper.cs @@ -13,6 +13,10 @@ using System.IO; using System.Linq; using System; using Sledgemapper.Shared.Entities; +using Sledgemapper.UI; +using System.Net; +using System.Net.Http; +using Refit; namespace Sledgemapper { @@ -56,6 +60,7 @@ namespace Sledgemapper var menuFileLoad = new MenuItem("_file_load", "Load"); var menuFileSave = new MenuItem("_file_save", "Save"); var menuConnect = new MenuItem("_connect", "Connect"); + var menuConnectLogin = new MenuItem("_connect_login", "Login"); var menuConnectNew = new MenuItem("_connect_new", "New"); var menuConnectJoin = new MenuItem("_connect_join", "Join"); var menuConnectSync = new MenuItem("_connect_sync", "Sync"); @@ -63,9 +68,11 @@ namespace Sledgemapper menuConnectSync.Selected += OnMenuConnectSyncSelected; menuFileLoad.Selected += OnMenuFileLoadSelected; menuFileSave.Selected += OnMenuFileSaveSelected; + menuConnectLogin.Selected += OnMenuConnectLoginSelected; menuConnectNew.Selected += OnMenuConnectNewSelected; menuConnectJoin.Selected += OnMenuConnectJoinSelected; + menuConnect.Items.Add(menuConnectLogin); menuConnect.Items.Add(menuConnectNew); menuConnect.Items.Add(menuConnectJoin); menuConnect.Items.Add(menuConnectSync); @@ -84,121 +91,270 @@ namespace Sledgemapper { Title = "Join mapping session" }; - var content = new VerticalStackPanel(); - var grid = new Grid - { - Width = 200, - ShowGridLines = false, - ColumnSpacing = 8, - RowSpacing = 3, - }; - // Set partitioning configuration - grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto)); - grid.ColumnsProportions.Add(new Proportion(ProportionType.Fill)); - grid.RowsProportions.Add(new Proportion(ProportionType.Auto)); - grid.RowsProportions.Add(new Proportion(ProportionType.Auto)); - var sessionNameLabel = new Label { Text = "Session Name:" }; - var initialsLabel = new Label { Text = "Initials:", GridRow = 1 }; - var textbox = new TextBox { GridColumn = 1 }; - var initialsTextbox = new TextBox { GridColumn = 1, GridRow = 1 }; - TextButton button = new TextButton - { - Text = "Start", - HorizontalAlignment = HorizontalAlignment.Center - }; - grid.Widgets.Add(textbox); - grid.Widgets.Add(initialsTextbox); - grid.Widgets.Add(sessionNameLabel); - grid.Widgets.Add(initialsLabel); - - content.Widgets.Add(grid); - - button.Click += async (s, e) => - { - if (string.IsNullOrWhiteSpace(textbox.Text)) - { - return; - } - if (_communicationManager.Connection.State != HubConnectionState.Connected) - { await _communicationManager.Connection.StartAsync(); } - var successful = false; - try - { - var result = await _communicationManager.Connection?.InvokeAsync("JoinSession", textbox.Text, initialsTextbox.Text); - if (result != null) - { - _sessionData.Map = result.Map; - _sessionData.Walls = result.Walls; - _sessionData.Overlays = result.Overlays; - _sessionData.Players = result.Players; - _sessionData.MapEntityAdded += OnMapEntityAdded; - - } - successful = result != null; ; - } - catch { } - if (successful) - { - _sessionData.SessionName = textbox.Text; - window.Close(); - } - }; - - content.Widgets.Add(button); + var content = new SessionWindow(); + content.BtnLogin.Text = "Join"; + content.BtnLogin.Click += OnButtonJoinSessionClicked; window.Content = content; window.ShowModal(_desktop); } + private async void OnButtonJoinSessionClicked(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 SessionWindow; + var isValid = ValidateTextbox(localContent.TxtSession); + if (!isValid) + { + return; + } + + if (_communicationManager.Connection.State != HubConnectionState.Connected) + { + await _communicationManager.Connection.StartAsync(); + } + + var successful = false; + try + { + var result = await _communicationManager.Connection?.InvokeAsync("JoinSession", localContent.TxtSession.Text, _authResponse.Initials); + if (result != null) + { + _sessionData.Map = result.Map; + _sessionData.Walls = result.Walls; + _sessionData.Overlays = result.Overlays; + _sessionData.Players = result.Players; + _sessionData.MapEntityAdded += OnMapEntityAdded; + _sessionData.MapEntityDeleted += OnMapEntityDeleted; + } + successful = result != null; ; + } + catch { } + if (successful) + { + _sessionData.SessionName = localContent.TxtSession.Text; + localWindow.Close(); + } + } + + private AuthenticateResponse _authResponse; + + private void OnMenuConnectLoginSelected(object sender, EventArgs e) + { + Window window = new Window + { + Title = "Login" + }; + + var content = new LoginRegisterWindow(); + content.RdoLogin.IsPressed = true; + content.RdoLogin.Click += (s, e) => + { + content.TxtFirstname.Visible = false; + content.TxtLastname.Visible = false; + content.TxtInitials.Visible = false; + content.LblFirstname.Visible = false; + content.LblLastname.Visible = false; + content.LblInitials.Visible = false; + content.BtnLogin.Visible = true; + content.BtnRegister.Visible = false; + window.Title = "Login"; + }; + + content.RdoRegister.Click += (s, e) => + { + content.TxtFirstname.Visible = true; + content.TxtLastname.Visible = true; + content.TxtInitials.Visible = true; + content.LblFirstname.Visible = true; + content.LblLastname.Visible = true; + content.LblInitials.Visible = true; + content.BtnLogin.Visible = false; + content.BtnRegister.Visible = true; + window.Title = "Register"; + }; + + content.BtnRegister.Click += OnButtonRegisterClick; + content.BtnLogin.Click += OnButtonLoginClick; + + window.Content = content; + window.ShowModal(_desktop); + } + + private async void OnButtonLoginClick(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 LoginRegisterWindow; + var isValid = true; + isValid &= ValidateTextbox(localContent.TxtEmail); + isValid &= ValidateTextbox(localContent.TxtPassword); + + if (!isValid) + { + return; + } + + var successful = false; + try + { + var httpClientHandler = new HttpClientHandler(); + + //if (myConfigurationService.VerifySslCertificate == false) + //{ + httpClientHandler.ServerCertificateCustomValidationCallback = + (message, certificate, chain, sslPolicyErrors) => true; + + var identiyApi = RestService.For( + new HttpClient(httpClientHandler) + { + BaseAddress = new Uri("http://localhost:4000") + }); + + _authResponse = await identiyApi.Authenticate(new AuthenticateModel + { + Username = localContent.TxtEmail.Text, + Password = localContent.TxtPassword.Text + }); + successful = true; + } + catch (Exception ex) + { + + } + if (successful) + { + localWindow.Close(); + }; + } + + private bool ValidateTextbox(TextBox textBox) + { + var valid = !string.IsNullOrWhiteSpace(textBox.Text); + if (!valid) + { + textBox.Background = new SolidBrush(Color.Red); + } + return valid; + } + + private async void OnButtonRegisterClick(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 LoginRegisterWindow; + var isValid = true; + isValid &= ValidateTextbox(localContent.TxtEmail); + isValid &= ValidateTextbox(localContent.TxtPassword); + isValid &= ValidateTextbox(localContent.TxtFirstname); + isValid &= ValidateTextbox(localContent.TxtLastname); + isValid &= ValidateTextbox(localContent.TxtInitials); + + if (!isValid) + { + return; + } + + var successful = false; + try + { + var httpClientHandler = new HttpClientHandler(); + + //if (myConfigurationService.VerifySslCertificate == false) + //{ + httpClientHandler.ServerCertificateCustomValidationCallback = + (message, certificate, chain, sslPolicyErrors) => true; + + var identiyApi = RestService.For( + new HttpClient(httpClientHandler) + { + BaseAddress = new Uri("http://localhost:4000") + }); + var result = await identiyApi.Register(new RegisterModel + { + Username = localContent.TxtEmail.Text, + Password = localContent.TxtPassword.Text, + FirstName = localContent.TxtFirstname.Text, + LastName = localContent.TxtLastname.Text, + Initials = localContent.TxtInitials.Text + }); + if (result.IsSuccessStatusCode) + { + _authResponse = await identiyApi.Authenticate(new AuthenticateModel + { + Username = localContent.TxtEmail.Text, + Password = localContent.TxtPassword.Text + }); + successful = true; + } + } + catch (Exception ex) + { + + } + if (successful) + { + localWindow.Close(); + }; + } + private void OnMenuConnectNewSelected(object sender, EventArgs e) { Window window = new Window { Title = "New mapping session" }; - var content = new VerticalStackPanel(); - var grid = new Grid - { - Width = 200, - ShowGridLines = false, - ColumnSpacing = 8, - RowSpacing = 3, - }; - // Set partitioning configuration - grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto)); - grid.ColumnsProportions.Add(new Proportion(ProportionType.Fill)); - grid.RowsProportions.Add(new Proportion(ProportionType.Auto)); - grid.RowsProportions.Add(new Proportion(ProportionType.Auto)); - var sessionNameLabel = new Label { Text = "Session Name:" }; - var initialsLabel = new Label { Text = "Initials:", GridRow = 1 }; - var textbox = new TextBox { GridColumn = 1 }; - var initialsTextbox = new TextBox { GridColumn = 1, GridRow = 1 }; - TextButton button = new TextButton - { - Text = "Start", - HorizontalAlignment = HorizontalAlignment.Center - }; - grid.Widgets.Add(textbox); - grid.Widgets.Add(initialsTextbox); - grid.Widgets.Add(sessionNameLabel); - grid.Widgets.Add(initialsLabel); + var content = new SessionWindow(); + content.BtnLogin.Text = "Join"; + content.BtnLogin.Click += OnButtonNewSessionClicked; + window.Content = content; - content.Widgets.Add(grid); + window.ShowModal(_desktop); - button.Click += async (s, e) => + + } + + private async void OnButtonNewSessionClicked(object sender, EventArgs e) + { + Container container = ((TextButton)sender).Parent; + while (!(container is Window)) { - if (string.IsNullOrWhiteSpace(textbox.Text)) - { - return; - } - if (_communicationManager.Connection.State != HubConnectionState.Connected) - { await _communicationManager.Connection.StartAsync(); } - var successful = false; - try - { - var session = await _communicationManager.Connection?.InvokeAsync("NewSession", textbox.Text, initialsTextbox.Text); + container = container.Parent; + } + var localWindow = (Window)container; + var localContent = localWindow.Content as SessionWindow; + var isValid = ValidateTextbox(localContent.TxtSession); + if (!isValid) + { + return; + } + + if (_communicationManager.Connection.State != HubConnectionState.Connected) + { + await _communicationManager.Connection.StartAsync(); + } + + var successful = false; + try + { + var session = await _communicationManager.Connection?.InvokeAsync("NewSession", localContent.TxtSession.Text, _authResponse.Initials); if (session != null) { _sessionData = session; @@ -208,29 +364,14 @@ namespace Sledgemapper } successful = session != null; - } - catch (Exception ex) - { - - } - if (successful) - { - _sessionData.SessionName = textbox.Text; - _communicationManager.SessionData = _sessionData; - window.Close(); - } - }; - - - content.Widgets.Add(button); - window.Content = content; - - window.Closed += (s, a) => + } + catch { } + if (successful) { - // Called when window is closed - }; - - window.ShowModal(_desktop); + _sessionData.SessionName = localContent.TxtSession.Text; + _communicationManager.SessionData = _sessionData; + localWindow.Close(); + } } private void OnMenuFileSaveSelected(object sender, EventArgs e) diff --git a/Sledgemapper/UI/LoginRegisterWindow.Generated.cs b/Sledgemapper/UI/LoginRegisterWindow.Generated.cs new file mode 100644 index 0000000..43a48d1 --- /dev/null +++ b/Sledgemapper/UI/LoginRegisterWindow.Generated.cs @@ -0,0 +1,153 @@ +/* Generated by MyraPad at 10/11/2020 11:32:04 */ +using Myra.Graphics2D; +using Myra.Graphics2D.TextureAtlases; +using Myra.Graphics2D.UI; +using Myra.Graphics2D.Brushes; + +#if !STRIDE +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +#else +using Stride.Core.Mathematics; +#endif + +namespace Sledgemapper.UI +{ + partial class LoginRegisterWindow: VerticalStackPanel + { + private void BuildUI() + { + RdoLogin = new RadioButton(); + RdoLogin.Text = " Login"; + RdoLogin.Id = "RdoLogin"; + + RdoRegister = new RadioButton(); + RdoRegister.Text = " Register"; + RdoRegister.Id = "RdoRegister"; + + var horizontalStackPanel1 = new HorizontalStackPanel(); + horizontalStackPanel1.Spacing = 18; + horizontalStackPanel1.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + horizontalStackPanel1.Widgets.Add(RdoLogin); + horizontalStackPanel1.Widgets.Add(RdoRegister); + + var label1 = new Label(); + label1.Text = "Email"; + + var label2 = new Label(); + label2.Text = "Password"; + label2.GridRow = 1; + + TxtEmail = new TextBox(); + TxtEmail.GridColumn = 1; + TxtEmail.Id = "TxtEmail"; + + TxtPassword = new TextBox(); + TxtPassword.PasswordField = true; + TxtPassword.GridColumn = 1; + TxtPassword.GridRow = 1; + TxtPassword.Id = "TxtPassword"; + + LblFirstname = new Label(); + LblFirstname.Text = "First name"; + LblFirstname.GridRow = 2; + LblFirstname.Visible = false; + LblFirstname.Id = "LblFirstname"; + + LblLastname = new Label(); + LblLastname.Text = "Last name"; + LblLastname.GridRow = 3; + LblLastname.Visible = false; + LblLastname.Id = "LblLastname"; + + LblInitials = new Label(); + LblInitials.Text = "Initials"; + LblInitials.GridRow = 4; + LblInitials.Visible = false; + LblInitials.Id = "LblInitials"; + + TxtFirstname = new TextBox(); + TxtFirstname.GridColumn = 1; + TxtFirstname.GridRow = 2; + TxtFirstname.Visible = false; + TxtFirstname.Id = "TxtFirstname"; + + TxtLastname = new TextBox(); + TxtLastname.GridColumn = 1; + TxtLastname.GridRow = 3; + TxtLastname.Visible = false; + TxtLastname.Id = "TxtLastname"; + + TxtInitials = new TextBox(); + TxtInitials.GridColumn = 1; + TxtInitials.GridRow = 4; + TxtInitials.Visible = false; + TxtInitials.Id = "TxtInitials"; + + var grid1 = new Grid(); + grid1.ColumnSpacing = 25; + grid1.RowSpacing = 10; + grid1.ColumnsProportions.Add(new Proportion + { + Type = Myra.Graphics2D.UI.ProportionType.Pixels, + Value = 80, + }); + grid1.ColumnsProportions.Add(new Proportion + { + Type = Myra.Graphics2D.UI.ProportionType.Fill, + }); + grid1.Widgets.Add(label1); + grid1.Widgets.Add(label2); + grid1.Widgets.Add(TxtEmail); + grid1.Widgets.Add(TxtPassword); + grid1.Widgets.Add(LblFirstname); + grid1.Widgets.Add(LblLastname); + grid1.Widgets.Add(LblInitials); + grid1.Widgets.Add(TxtFirstname); + grid1.Widgets.Add(TxtLastname); + grid1.Widgets.Add(TxtInitials); + + BtnLogin = new TextButton(); + BtnLogin.Text = "Login"; + BtnLogin.Width = 70; + BtnLogin.Height = 20; + BtnLogin.Padding = new Thickness(5); + BtnLogin.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + BtnLogin.Id = "BtnLogin"; + + BtnRegister = new TextButton(); + BtnRegister.Text = "Register"; + BtnRegister.Visible = false; + BtnRegister.Width = 70; + BtnRegister.Height = 20; + BtnRegister.Padding = new Thickness(5); + BtnRegister.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + BtnRegister.Id = "BtnRegister"; + + + Spacing = 16; + HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center; + Width = 400; + Padding = new Thickness(10); + Widgets.Add(horizontalStackPanel1); + Widgets.Add(grid1); + Widgets.Add(BtnLogin); + Widgets.Add(BtnRegister); + } + + + public RadioButton RdoLogin; + public RadioButton RdoRegister; + public TextBox TxtEmail; + public TextBox TxtPassword; + public Label LblFirstname; + public Label LblLastname; + public Label LblInitials; + public TextBox TxtFirstname; + public TextBox TxtLastname; + public TextBox TxtInitials; + public TextButton BtnLogin; + public TextButton BtnRegister; + } +} \ No newline at end of file diff --git a/Sledgemapper/UI/LoginRegisterWindow.cs b/Sledgemapper/UI/LoginRegisterWindow.cs new file mode 100644 index 0000000..f6752f8 --- /dev/null +++ b/Sledgemapper/UI/LoginRegisterWindow.cs @@ -0,0 +1,11 @@ +/* Generated by MyraPad at 09/11/2020 23:54:08 */ +namespace Sledgemapper.UI +{ + public partial class LoginRegisterWindow + { + public LoginRegisterWindow() + { + BuildUI(); + } + } +} \ No newline at end of file diff --git a/Sledgemapper/UI/SessionWindow.Generated.cs b/Sledgemapper/UI/SessionWindow.Generated.cs new file mode 100644 index 0000000..a0c4cef --- /dev/null +++ b/Sledgemapper/UI/SessionWindow.Generated.cs @@ -0,0 +1,62 @@ +/* Generated by MyraPad at 10/11/2020 10:59:36 */ +using Myra.Graphics2D; +using Myra.Graphics2D.TextureAtlases; +using Myra.Graphics2D.UI; +using Myra.Graphics2D.Brushes; + +#if !STRIDE +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +#else +using Stride.Core.Mathematics; +#endif + +namespace Sledgemapper.UI +{ + partial class SessionWindow: VerticalStackPanel + { + private void BuildUI() + { + var label1 = new Label(); + label1.Text = "Session"; + + TxtSession = new TextBox(); + TxtSession.GridColumn = 1; + TxtSession.Id = "TxtSession"; + + 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(TxtSession); + + BtnLogin = new TextButton(); + BtnLogin.Text = "Join"; + BtnLogin.Padding = new Thickness(10, 5); + BtnLogin.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + BtnLogin.Id = "BtnLogin"; + + + 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(BtnLogin); + } + + + public TextBox TxtSession; + public TextButton BtnLogin; + } +} \ No newline at end of file diff --git a/Sledgemapper/UI/SessionWindow.cs b/Sledgemapper/UI/SessionWindow.cs new file mode 100644 index 0000000..3c7a99a --- /dev/null +++ b/Sledgemapper/UI/SessionWindow.cs @@ -0,0 +1,11 @@ +/* Generated by MyraPad at 10/11/2020 10:59:36 */ +namespace Sledgemapper.UI +{ + public partial class SessionWindow + { + public SessionWindow() + { + BuildUI(); + } + } +} \ No newline at end of file diff --git a/Sledgemapper/UI/loginwindow.xml b/Sledgemapper/UI/loginwindow.xml new file mode 100644 index 0000000..a8559ec --- /dev/null +++ b/Sledgemapper/UI/loginwindow.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sledgemapper/UI/sessionwindow.xml b/Sledgemapper/UI/sessionwindow.xml new file mode 100644 index 0000000..4c4e968 --- /dev/null +++ b/Sledgemapper/UI/sessionwindow.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file