mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:26:31 +00:00
do not use Loader to check creds
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Azaion.Common;
|
||||
using MessagePack;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetMQ;
|
||||
using NetMQ.Sockets;
|
||||
|
||||
|
||||
namespace Azaion.LoaderUI;
|
||||
|
||||
@@ -41,24 +36,23 @@ public partial class Login
|
||||
|
||||
private async void LoginClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var creds = new ApiCredentials
|
||||
var credentials = new ApiCredentials
|
||||
{
|
||||
Email = TbEmail.Text,
|
||||
Password = TbPassword.Password
|
||||
};
|
||||
if (string.IsNullOrWhiteSpace(creds.Email) || string.IsNullOrWhiteSpace(creds.Password))
|
||||
if (string.IsNullOrWhiteSpace(credentials.Email) || string.IsNullOrWhiteSpace(credentials.Password))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
SetControlsStatus(isLoading: true);
|
||||
_azaionApi.Login(creds);
|
||||
Validate(creds);
|
||||
await _azaionApi.Validate(credentials);
|
||||
|
||||
TbStatus.Foreground = Brushes.Black;
|
||||
var localVersion = Constants.GetLocalVersion();
|
||||
var installerVersion = await GetInstallerVer() ?? localVersion;
|
||||
var credsEncrypted = Security.Encrypt(creds);
|
||||
var credsEncrypted = Security.Encrypt(credentials);
|
||||
|
||||
if (installerVersion > localVersion)
|
||||
{
|
||||
@@ -97,69 +91,6 @@ public partial class Login
|
||||
}
|
||||
}
|
||||
|
||||
private void Validate(ApiCredentials creds)
|
||||
{
|
||||
var dealer = new DealerSocket();
|
||||
try
|
||||
{
|
||||
using var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = Constants.EXTERNAL_LOADER_PATH,
|
||||
Arguments = $"--port {ConstantsLoader.EXTERNAL_LOADER_PORT} --api {Constants.DEFAULT_API_URL}",
|
||||
CreateNoWindow = true
|
||||
};
|
||||
process.Start();
|
||||
dealer.Options.Identity = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("N"));
|
||||
dealer.Connect($"tcp://{Constants.DEFAULT_ZMQ_INFERENCE_HOST}:{ConstantsLoader.EXTERNAL_LOADER_PORT}");
|
||||
|
||||
var result = SendCommand(dealer, RemoteCommand.Create(CommandType.Login, creds));
|
||||
if (result.CommandType != CommandType.Ok)
|
||||
throw new Exception(result.Message);
|
||||
|
||||
result = SendCommand(dealer, RemoteCommand.Create(CommandType.CheckResource));
|
||||
if (result.CommandType != CommandType.Ok)
|
||||
throw new Exception(result.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SendCommand(dealer, RemoteCommand.Create(CommandType.Exit));
|
||||
dealer.Close();
|
||||
dealer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private RemoteCommand SendCommand(DealerSocket dealer, RemoteCommand command, int retryCount = 30, int retryDelayMs = 800)
|
||||
{
|
||||
try
|
||||
{
|
||||
dealer.SendFrame(MessagePackSerializer.Serialize(command));
|
||||
|
||||
var tryNum = 0;
|
||||
while (tryNum++ < retryCount)
|
||||
{
|
||||
if (!dealer.TryReceiveFrameBytes(TimeSpan.FromMilliseconds(retryDelayMs), out var bytes))
|
||||
continue;
|
||||
var res = MessagePackSerializer.Deserialize<RemoteCommand>(bytes);
|
||||
if (res.CommandType == CommandType.Error)
|
||||
throw new Exception(res.Message);
|
||||
return res;
|
||||
}
|
||||
|
||||
throw new Exception($"Sent {command} {retryCount} times, with wait time {retryDelayMs}ms for each call. No response from client.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Version?> GetInstallerVer()
|
||||
{
|
||||
TbStatus.Text = "Checking for the newer version...";
|
||||
|
||||
Reference in New Issue
Block a user