about summary refs log tree commit diff
path: root/ModerationClient/ViewModels/LoginViewModel.cs
blob: 34c8d28b038a6137a6d8cc99c7756d7cdc50fc64 (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 System;
using System.Threading.Tasks;
using LibMatrix.Services;
using ModerationClient.Services;

namespace ModerationClient.ViewModels;

public partial class LoginViewModel(MatrixAuthenticationService authService, HomeserverResolverService hsResolver) : ViewModelBase
{
    private Exception? _exception;
    public string Username { get; set; }
    public string? Homeserver { get; set; }
    public string Password { get; set; }

    public Exception? Exception {
        get => _exception;
        private set => SetProperty(ref _exception, value);
    }

    public async Task ResolveHomeserverAsync() {
        try {
            string[] parts = Username.Split(':', 2);
            Homeserver = (await hsResolver.ResolveHomeserverFromWellKnown(Username, enableServer: false)).Client;
        } catch (Exception e) {
            Console.WriteLine(e);
        }
    }

    public async Task LoginAsync() {
        try {
            Exception = null;
            await authService.LoginAsync(Username, Password);
        } catch (Exception e) {
            Exception = e;
        }
    }
}