1
0

60 lines
1.6 KiB
C#

using System;
using System.Threading.Tasks;
using Flawless.Client.Remote;
using Flawless.Client.Service;
using ReactiveUI;
using ReactiveUI.SourceGenerators;
using Refit;
namespace Flawless.Client.ViewModels;
public partial class FirstSetupViewModel : ViewModelBase, IRoutableViewModel
{
public string? UrlPathSegment { get; } = Guid.NewGuid().ToString();
public IScreen HostScreen { get; }
[Reactive] private string _email;
[Reactive] private string _username;
[Reactive] private string _password;
public FirstSetupViewModel(IScreen hostScreen)
{
HostScreen = hostScreen;
}
[ReactiveCommand]
private async Task SetupAsync()
{
try
{
using var l = UIHelper.MakeLoading("Setup...");
await Api.C.Gateway.FirstSetup(new FirstSetupRequest()
{
AdminEmail = Email,
AdminUsername = Username,
AdminPassword = Password
});
await Api.C.LoginAsync(Username, Password);
Api.C.Status.Value!.RequireInitialization = false;
}
catch (ApiException ex)
{
await Console.Error.WriteLineAsync($"Register as '{Username}' Failed: {ex.Content}");
UIHelper.NotifyError(ex);
}
catch (Exception ex)
{
await Console.Error.WriteLineAsync($"Register as '{Username}' Failed: {ex}");
UIHelper.NotifyError(ex);
}
Console.WriteLine($"Register as '{Username}' success!");
}
}