about summary refs log tree commit diff
path: root/MatrixRoomUtils.Desktop/LoginWindow.axaml.cs
blob: 183c46b0d2449b212bb53dab914201ebbca27315 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.VisualTree;

namespace MatrixRoomUtils.Desktop;

public partial class LoginWindow : Window {
    private readonly MRUStorageWrapper _storage;

    public LoginWindow(MRUStorageWrapper storage) {
        _storage = storage;
        InitializeComponent();
#if DEBUG
        this.AttachDevTools();
#endif
    }

    private void InitializeComponent() {
        AvaloniaXamlLoader.Load(this);
    }

    public string Username { get; set; }
    public string Password { get; set; }
    // ReSharper disable once AsyncVoidMethod
    private async void Login(object? sender, RoutedEventArgs e) {
        var res = await _storage.Login(Username.Split(':')[1], Username.Split(':')[0][1..], Password);
        if (res is not null) {
            await _storage.AddToken(res);
            Close();
        }
        else {
            Password = "";
        }
    }
}