This commit is contained in:
kp9lk
2026-11-27 10:00:32 +03:00
commit 7de029b4bd
13 changed files with 278 additions and 0 deletions
@@ -0,0 +1,4 @@
<Solution>
<Project Path="SampleApi/SampleApi.csproj" />
<Project Path="SampleDesktop/SampleDesktop.csproj" />
</Solution>
+25
View File
@@ -0,0 +1,25 @@
List<User> users =
[
new(1, "Алексей Смирнов", "alexey.smirnov@example.com", "P@ssw0rd123"),
new(2, "Елена Кузнецова", "elena.kuznetsova@example.com", "Qwerty2026!"),
new(3, "Дмитрий Попов", "dmitry.popov@example.com", "Dm1try#Pass"),
new(4, "Мария Соколова", "maria.sokolova@example.com", "Masha_9988"),
new(5, "Иван Лебедев", "ivan.lebedev@example.com", "Iv@n_Strong1")
];
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapPost("/auth/signin", (AuthRequest request) =>
{
var findUser = users.FirstOrDefault(it => it.Email == request.Email);
if (findUser == null) return Results.NotFound();
if (findUser.Password != request.Password) return Results.Unauthorized();
return Results.Ok(new AuthResponse("bebebebebebebebebebebebbebebebe"));
});
app.Run();
record User(int Id, string Name, string Email, string Password);
record AuthRequest(string Email, string Password);
record AuthResponse(string token);
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5120",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7112;http://localhost:5120",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
@@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SampleDesktop.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
@@ -0,0 +1,23 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace SampleDesktop;
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new LoginWindow();
}
base.OnFrameworkInitializationCompleted();
}
}
@@ -0,0 +1,28 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SampleDesktop.LoginWindow"
Title="SampleDesktop">
<StackPanel
Orientation="Vertical"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="10"
MinWidth="250">
<TextBlock Text="Email"/>
<TextBox
Name="LoginBox"
PlaceholderText="Введите логин"/>
<TextBlock Text="Password"/>
<TextBox
Name="Password"
PlaceholderText="Введите пароль"/>
<Button Name="LoginButton"
Content="Войти"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Click="LoginButton_OnClick"/>
</StackPanel>
</Window>
@@ -0,0 +1,36 @@
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);
}
}
}
@@ -0,0 +1,24 @@
using Avalonia;
using System;
namespace SampleDesktop;
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
#if DEBUG
.WithDeveloperTools()
#endif
.WithInterFont()
.LogToTrace();
}
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="12.1.4" />
<PackageReference Include="Avalonia.Desktop" Version="12.1.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.1.4" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.1.4" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embedded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="SampleDesktop.Desktop"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>