2023-01-06 00:37:13 +00:00
|
|
|
|
using LANCommander.SDK.Models;
|
|
|
|
|
using Playnite.SDK;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
2023-01-08 18:09:57 +00:00
|
|
|
|
namespace LANCommander.PlaynitePlugin.Views
|
2023-01-06 00:37:13 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class Authentication : UserControl
|
|
|
|
|
{
|
2023-01-14 21:15:31 +00:00
|
|
|
|
private LANCommanderLibraryPlugin Plugin;
|
2023-01-06 00:37:13 +00:00
|
|
|
|
private ViewModels.Authentication Context { get { return (ViewModels.Authentication)DataContext; } }
|
|
|
|
|
|
2023-01-14 21:15:31 +00:00
|
|
|
|
public Authentication(LANCommanderLibraryPlugin plugin)
|
2023-01-06 00:37:13 +00:00
|
|
|
|
{
|
|
|
|
|
Plugin = plugin;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TextBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
2023-01-16 02:45:37 +00:00
|
|
|
|
if (e.Key == System.Windows.Input.Key.Enter || e.Key == System.Windows.Input.Key.Return)
|
2023-01-06 00:37:13 +00:00
|
|
|
|
{
|
|
|
|
|
Authenticate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoginButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Authenticate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Password_PasswordChanged(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DataContext != null)
|
|
|
|
|
{
|
|
|
|
|
((ViewModels.Authentication)DataContext).Password = ((PasswordBox)sender).Password;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Authenticate()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-01-26 03:08:05 +00:00
|
|
|
|
if (Plugin.LANCommander == null || Plugin.LANCommander.Client == null)
|
2023-01-07 18:34:12 +00:00
|
|
|
|
Plugin.LANCommander = new LANCommanderClient(Context.ServerAddress);
|
|
|
|
|
else
|
|
|
|
|
Plugin.LANCommander.Client.BaseUrl = new Uri(Context.ServerAddress);
|
|
|
|
|
|
2023-01-06 00:37:13 +00:00
|
|
|
|
var response = Plugin.LANCommander.Authenticate(Context.UserName, Context.Password);
|
|
|
|
|
|
2023-01-07 18:34:12 +00:00
|
|
|
|
Plugin.Settings.ServerAddress = Context.ServerAddress;
|
|
|
|
|
Plugin.Settings.AccessToken = response.AccessToken;
|
|
|
|
|
Plugin.Settings.RefreshToken = response.RefreshToken;
|
2023-01-06 00:37:13 +00:00
|
|
|
|
|
|
|
|
|
// Probably unneeded, but why not be more secure?
|
|
|
|
|
Context.Password = String.Empty;
|
|
|
|
|
|
2023-01-12 02:48:39 +00:00
|
|
|
|
Plugin.SavePluginSettings(Plugin.Settings);
|
2023-01-06 00:37:13 +00:00
|
|
|
|
|
|
|
|
|
Window.GetWindow(this).Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Plugin.PlayniteApi.Dialogs.ShowErrorMessage(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|