@page "/Login" @using System.Text.Json @using System.Text.Json.Serialization @using LibMatrix

Login


@@:
Add account to queue Log in

Import from TSV


Import credentials from a TSV (Tab Separated Values) file
Columns: username, homeserver, password, proxy
Keep in mind there is no column header!



@foreach (var record in records) { var r = record; @if (r.Exception is MatrixException me) { } else if (r.Exception is { } e) { } }
Username Homeserver Password Proxy Actions
Remove
Exception: @me.ErrorCode @me.Error
Exception: @e.Message

Log in @code { readonly List records = new(); private LoginStruct newRecordInput = new(); List? LoggedInSessions { get; set; } = new(); async Task LoginAll() { var loginTasks = records.Select(Login); await Task.WhenAll(loginTasks); } async Task Login(LoginStruct record) { if (!records.Contains(record)) records.Add(record); if (LoggedInSessions.Any(x => x.UserId == $"@{record.Username}:{record.Homeserver}" && x.Proxy == record.Proxy)) return; StateHasChanged(); try { var result = new UserAuth(await hsProvider.Login(record.Homeserver, record.Username, record.Password, record.Proxy)) { Proxy = record.Proxy }; if (result == null) { Console.WriteLine($"Failed to login to {record.Homeserver} as {record.Username}!"); return; } Console.WriteLine($"Obtained access token for {result.UserId}!"); await RMUStorage.AddToken(result); LoggedInSessions = await RMUStorage.GetAllTokens(); } catch (Exception e) { Console.WriteLine($"Failed to login to {record.Homeserver} as {record.Username}!"); Console.WriteLine(e); record.Exception = e; } StateHasChanged(); } private async Task FileChanged(InputFileChangeEventArgs obj) { LoggedInSessions = await RMUStorage.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(new() { Homeserver = parts[0], Username = parts[1], Password = parts[2], Proxy = via }); } } private async Task AddRecord() { LoggedInSessions = await RMUStorage.GetAllTokens(); records.Add(newRecordInput); newRecordInput = new(); } private class LoginStruct { public string? Homeserver { get; set; } = ""; public string? Username { get; set; } = ""; public string? Password { get; set; } = ""; public string? Proxy { get; set; } [JsonIgnore] internal Exception? Exception { get; set; } } }