@page "/Login" @using System.Text.Json @inject ILocalStorageService LocalStorage @inject IJSRuntime JsRuntime

Login


@@: via



Parsed records


@foreach (var record in records) { var r = record; }
Username Homeserver Password Proxy
Remove


@code { readonly List<(string homeserver, string username, string password, string? proxy)> records = new(); (string homeserver, string username, string password, string? proxy) newRecordInput = ("", "", "", null); List? LoggedInSessions { get; set; } = new(); async Task Login() { var loginTasks = records.Select(async record => { var (homeserver, username, password, proxy) = record; if (LoggedInSessions.Any(x => x.UserId == $"@{username}:{homeserver}" && x.Proxy == proxy)) return; try { var result = new UserAuth(await hsProvider.Login(homeserver, username, password, proxy)) { Proxy = proxy }; if (result == null) { Console.WriteLine($"Failed to login to {homeserver} as {username}!"); return; } Console.WriteLine($"Obtained access token for {result.UserId}!"); await MRUStorage.AddToken(result); LoggedInSessions = await MRUStorage.GetAllTokens(); } catch (Exception e) { Console.WriteLine($"Failed to login to {homeserver} as {username}!"); Console.WriteLine(e); } StateHasChanged(); }); await Task.WhenAll(loginTasks); } private async Task FileChanged(InputFileChangeEventArgs obj) { LoggedInSessions = await MRUStorage.GetAllTokens(); Console.WriteLine(JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true })); await using var rs = obj.File.OpenReadStream(); using var sr = new StreamReader(rs); var tsvData = await sr.ReadToEndAsync(); records.Clear(); foreach (var line in tsvData.Split('\n')) { string?[] parts = line.Split('\t'); if (parts.Length < 3) continue; string? via = parts.Length > 3 ? parts[3] : null; records.Add((parts[0], parts[1], parts[2], via)); } } private async Task AddRecord() { LoggedInSessions = await MRUStorage.GetAllTokens(); records.Add(newRecordInput); newRecordInput = ("", "", "", null); } }