36 lines
986 B
C#
36 lines
986 B
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
|
|
namespace SampleDesktop;
|
|
record AuthRequest(string Email, string Password);
|
|
record AuthResponse(string token);
|
|
public partial class LoginWindow : Window
|
|
{
|
|
public LoginWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private async void LoginButton_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
HttpClient client = new();
|
|
client.BaseAddress = new Uri("http://localhost:5120/");
|
|
var request = new AuthRequest(
|
|
LoginBox.Text,
|
|
Password.Text
|
|
);
|
|
var result = await client.PostAsJsonAsync(
|
|
"/auth/signin",
|
|
request
|
|
);
|
|
Console.WriteLine(result.StatusCode);
|
|
if (result.IsSuccessStatusCode)
|
|
{
|
|
AuthResponse? token = await result.Content.ReadFromJsonAsync<AuthResponse>();
|
|
Console.WriteLine(token);
|
|
}
|
|
}
|
|
} |