about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/HSEInit.razor
blob: b2fc0db8bf7e54fb5522a0c3dd3fe198835b7569 (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
@page "/HSEInit"
@inject ILocalStorageService LocalStorage
@inject IJSRuntime JsRuntime
<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", "", ""));
            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;
    }
}