updates and bugfixes
This commit is contained in:
parent
19f1084d5f
commit
22233f8c6e
8 changed files with 85 additions and 32 deletions
|
@ -293,7 +293,14 @@ namespace Sledgemapper
|
|||
|
||||
_spriteBatch.End();
|
||||
|
||||
_desktop?.Render();
|
||||
try
|
||||
{
|
||||
_desktop?.Render();
|
||||
}
|
||||
catch
|
||||
{
|
||||
System.Console.WriteLine("Desktop render error");
|
||||
}
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
|
@ -556,7 +563,8 @@ namespace Sledgemapper
|
|||
|
||||
private async void OnButtonLoginClick(object sender, EventArgs e)
|
||||
{
|
||||
Container container = ((TextButton)sender).Parent;
|
||||
var button = ((TextButton)sender);
|
||||
Container container = button.Parent;
|
||||
while (!(container is Window))
|
||||
{
|
||||
container = container.Parent;
|
||||
|
@ -564,23 +572,30 @@ namespace Sledgemapper
|
|||
|
||||
var localWindow = (Window)container;
|
||||
var localContent = localWindow.Content as LoginRegisterWindow;
|
||||
|
||||
if (!button.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isValid = true;
|
||||
isValid &= ValidateTextbox(localContent.TxtEmail);
|
||||
isValid &= ValidateTextbox(localContent.TxtPassword);
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
localContent.LblLoginError.Text="Username or password is not valid";
|
||||
localContent.LblLoginError.Visible=true;
|
||||
|
||||
localContent.LblLoginError.Text = "Username or password is not valid";
|
||||
localContent.LblLoginError.Visible = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
try
|
||||
{
|
||||
localContent.LblLoginError.Text="";
|
||||
localContent.LblLoginError.Visible=false;
|
||||
button.Text = "Wait...";
|
||||
localContent.LblLoginError.Text = "";
|
||||
localContent.LblLoginError.Visible = false;
|
||||
_authResponse = await _communicationManager.Login(new AuthenticateModel
|
||||
{
|
||||
Username = localContent.TxtEmail.Text,
|
||||
|
@ -588,11 +603,20 @@ namespace Sledgemapper
|
|||
});
|
||||
successful = _authResponse != null;
|
||||
}
|
||||
catch (Refit.ApiException refitException)
|
||||
{
|
||||
localContent.LblLoginError.Text = refitException.Content;
|
||||
localContent.LblLoginError.Visible = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
localContent.LblLoginError.Text=ex.Message;
|
||||
localContent.LblLoginError.Visible=true;
|
||||
localContent.LblLoginError.Text = "Can't connect to the server";
|
||||
localContent.LblLoginError.Visible = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
button.Enabled = true;
|
||||
button.Text = "Login";
|
||||
}
|
||||
|
||||
if (successful)
|
||||
|
@ -608,7 +632,8 @@ namespace Sledgemapper
|
|||
|
||||
private async void OnButtonRegisterClick(object sender, EventArgs e)
|
||||
{
|
||||
Container container = ((TextButton)sender).Parent;
|
||||
var button = ((TextButton)sender);
|
||||
Container container = button.Parent;
|
||||
while (!(container is Window))
|
||||
{
|
||||
container = container.Parent;
|
||||
|
@ -616,6 +641,12 @@ namespace Sledgemapper
|
|||
|
||||
var localWindow = (Window)container;
|
||||
var localContent = localWindow.Content as LoginRegisterWindow;
|
||||
|
||||
if (!button.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isValid = true;
|
||||
isValid &= ValidateTextbox(localContent.TxtEmail);
|
||||
isValid &= ValidateTextbox(localContent.TxtPassword);
|
||||
|
@ -625,12 +656,18 @@ namespace Sledgemapper
|
|||
|
||||
if (!isValid)
|
||||
{
|
||||
localContent.LblLoginError.Text = "Please complete all the fields";
|
||||
localContent.LblLoginError.Visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
try
|
||||
{
|
||||
button.Text = "Wait...";
|
||||
localContent.LblLoginError.Text = "";
|
||||
localContent.LblLoginError.Visible = false;
|
||||
|
||||
var result = await _communicationManager.Register(new RegisterModel
|
||||
{
|
||||
Username = localContent.TxtEmail.Text,
|
||||
|
@ -649,9 +686,20 @@ namespace Sledgemapper
|
|||
successful = true;
|
||||
}
|
||||
}
|
||||
catch (Refit.ApiException refitException)
|
||||
{
|
||||
localContent.LblLoginError.Text = refitException.Content;
|
||||
localContent.LblLoginError.Visible = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
localContent.LblLoginError.Text = "Can't connect to the server";
|
||||
localContent.LblLoginError.Visible = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
button.Enabled = true;
|
||||
button.Text = "Register";
|
||||
}
|
||||
if (successful)
|
||||
{
|
||||
|
@ -659,6 +707,9 @@ namespace Sledgemapper
|
|||
_mainWidget.MenuConnectJoin.Enabled = true;
|
||||
_mainWidget.MenuConnectSync.Enabled = true;
|
||||
_mainWidget.MenuConnectUpload.Enabled = true;
|
||||
|
||||
_mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
||||
|
||||
localWindow.Close();
|
||||
}
|
||||
}
|
||||
|
@ -856,7 +907,11 @@ namespace Sledgemapper
|
|||
var valid = !string.IsNullOrWhiteSpace(textBox.Text);
|
||||
if (!valid)
|
||||
{
|
||||
textBox.Background = new SolidBrush(Color.PaleVioletRed);
|
||||
textBox.Background = new SolidBrush(Color.Red);
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox.Background = new SolidBrush(new Color(51, 51, 51)); ;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue