37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using FrontendAvalonia.Models;
|
|
using FrontendAvalonia.Services.GamenightApi;
|
|
using FrontendAvalonia.Views;
|
|
using ReactiveUI;
|
|
|
|
namespace FrontendAvalonia.ViewModels;
|
|
|
|
public class LoginViewModel : PageViewModelBase
|
|
{
|
|
private IGamenight GamenightApi { get; }
|
|
private GamenightModel Model { get; }
|
|
|
|
public string Username { get; set; } = string.Empty;
|
|
public string Password { get; set; } = string.Empty;
|
|
public ICommand LoginCommand { get; }
|
|
|
|
public LoginViewModel(IScreen screen, IGamenight gamenightApi, GamenightModel model)
|
|
:base(screen)
|
|
{
|
|
GamenightApi = gamenightApi;
|
|
Model = model;
|
|
|
|
LoginCommand = ReactiveCommand.CreateFromTask(Login);
|
|
}
|
|
|
|
private async Task Login()
|
|
{
|
|
var result = await GamenightApi.GetToken(new Login { Username = Username, Password = Password });
|
|
if (result is { IsSuccessStatusCode: true })
|
|
{
|
|
Model.UserToken = result.Content?.Jwt_token;
|
|
HostScreen.Router.NavigateBack.Execute();
|
|
}
|
|
}
|
|
} |