Change login button state when attempting to authenticate
This commit is contained in:
parent
8fbc72e343
commit
4277b50198
3 changed files with 20 additions and 5 deletions
|
@ -62,9 +62,9 @@ namespace LANCommander.PlaynitePlugin
|
||||||
return tempFile;
|
return tempFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthResponse Authenticate(string username, string password)
|
public async Task<AuthResponse> AuthenticateAsync(string username, string password)
|
||||||
{
|
{
|
||||||
var response = Client.Post<AuthResponse>(new RestRequest("/api/Auth").AddJsonBody(new AuthRequest()
|
var response = await Client.ExecuteAsync<AuthResponse>(new RestRequest("/api/Auth", Method.POST).AddJsonBody(new AuthRequest()
|
||||||
{
|
{
|
||||||
UserName = username,
|
UserName = username,
|
||||||
Password = password
|
Password = password
|
||||||
|
|
|
@ -214,6 +214,6 @@
|
||||||
<TextBox Grid.Row="1" Grid.Column="1" Name="Username" Text="{Binding UserName}" KeyDown="TextBox_KeyDown" />
|
<TextBox Grid.Row="1" Grid.Column="1" Name="Username" Text="{Binding UserName}" KeyDown="TextBox_KeyDown" />
|
||||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="Password" />
|
<TextBlock Grid.Row="2" Grid.Column="0" Text="Password" />
|
||||||
<PasswordBox Grid.Row="2" Grid.Column="1" Name="Password" PasswordChanged="Password_PasswordChanged" KeyDown="TextBox_KeyDown" />
|
<PasswordBox Grid.Row="2" Grid.Column="1" Name="Password" PasswordChanged="Password_PasswordChanged" KeyDown="TextBox_KeyDown" />
|
||||||
<Button Grid.Row="3" Grid.ColumnSpan="2" Click="LoginButton_Click" x:Name="LoginButton">Login</Button>
|
<Button Grid.Row="3" Grid.ColumnSpan="2" Command="{Binding LoginCommand}" x:Name="LoginButton">Login</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
@ -67,16 +68,30 @@ namespace LANCommander.PlaynitePlugin.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Authenticate()
|
public RelayCommand<object> LoginCommand
|
||||||
|
{
|
||||||
|
get => new RelayCommand<object>(async (a) =>
|
||||||
|
{
|
||||||
|
await Authenticate();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Authenticate()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
LoginButton.Dispatcher.Invoke(new System.Action(() =>
|
||||||
|
{
|
||||||
|
LoginButton.IsEnabled = false;
|
||||||
|
LoginButton.Content = "Logging in...";
|
||||||
|
}));
|
||||||
|
|
||||||
if (Plugin.LANCommander == null || Plugin.LANCommander.Client == null)
|
if (Plugin.LANCommander == null || Plugin.LANCommander.Client == null)
|
||||||
Plugin.LANCommander = new LANCommanderClient(Context.ServerAddress);
|
Plugin.LANCommander = new LANCommanderClient(Context.ServerAddress);
|
||||||
else
|
else
|
||||||
Plugin.LANCommander.Client.BaseUrl = new Uri(Context.ServerAddress);
|
Plugin.LANCommander.Client.BaseUrl = new Uri(Context.ServerAddress);
|
||||||
|
|
||||||
var response = Plugin.LANCommander.Authenticate(Context.UserName, Context.Password);
|
var response = await Plugin.LANCommander.AuthenticateAsync(Context.UserName, Context.Password);
|
||||||
|
|
||||||
Plugin.Settings.ServerAddress = Context.ServerAddress;
|
Plugin.Settings.ServerAddress = Context.ServerAddress;
|
||||||
Plugin.Settings.AccessToken = response.AccessToken;
|
Plugin.Settings.AccessToken = response.AccessToken;
|
||||||
|
|
Loading…
Add table
Reference in a new issue