about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/HSEInit.razor
blob: cabc6719afca90b5261f79386b9af884604fff1c (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
38
39
40
41
@page "/HSEInit"
@using Blazored.LocalStorage
@inject ILocalStorageService LocalStorage

<h3>HSE Initialising...</h3>
<hr/>

@code {

    protected override async Task OnInitializedAsync() {
        await base.OnInitializedAsync();
        var tasks = Enumerable.Range(0, 50).Select(i => Login()).ToList();
        await Task.WhenAll(tasks);
        Console.WriteLine("All logins complete!");
        var userAuths = tasks.Select(t => t.Result).Where(t => t != null).ToList();
        await LocalStorage.SetItemAsync("rmu.tokens", userAuths);
        NavigationManager.NavigateTo("/", true);
    }

    async Task<UserAuth?> Login() {
        try {
            var result = new UserAuth(await hsProvider.Login("http://localhost:5298", $"{Guid.NewGuid().ToString()}", ""));
            if (result == null) {
                Console.WriteLine($"Failed to login!");
                return null;
            }

            Console.WriteLine($"Obtained access token for {result.UserId}!");

            return result;
        }
        catch (Exception e) {
            // Console.WriteLine($"Failed to login to {record.Homeserver} as {record.Username}!");
            Console.WriteLine(e);
            // record.Exception = e;
        }

        return null;
    }

}