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

Login


@if (inputVisible.username) { } else { @newRecordInput.username } @if (inputVisible.homeserver) { } else { @newRecordInput.homeserver } @if (inputVisible.password) { } else { @string.Join("", newRecordInput.password.Select(x => '*')) }



Parsed records


@foreach (var (homeserver, username, password) in records) { }
@username @homeserver @password.Length chars


@code { List<(string homeserver, string username, string password)> records = new(); (string homeserver, string username, string password) newRecordInput = ("", "", ""); (bool homeserver, bool username, bool password) inputVisible = (false, false, false); async Task Login() { foreach (var (homeserver, username, password) in records) { if (RuntimeCache.LoginSessions.Any(x => x.Value.LoginResponse.UserId == $"@{username}:{homeserver}")) continue; var result = await MatrixAuth.Login(homeserver, username, password); Console.WriteLine($"Obtained access token for {result.UserId}!"); var userinfo = new UserInfo() { LoginResponse = result }; userinfo.Profile = await (await new AuthenticatedHomeServer(result.UserId, result.AccessToken, result.HomeServer).Configure()).GetProfile(result.UserId); RuntimeCache.LastUsedToken = result.AccessToken; RuntimeCache.LoginSessions.Add(result.AccessToken, userinfo); StateHasChanged(); } await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); } private async Task FileChanged(InputFileChangeEventArgs obj) { Console.WriteLine(JsonSerializer.Serialize(obj, new JsonSerializerOptions() { WriteIndented = true })); await using var rs = obj.File.OpenReadStream(); using var sr = new StreamReader(rs); string TsvData = await sr.ReadToEndAsync(); records.Clear(); foreach (var line in TsvData.Split('\n')) { var parts = line.Split('\t'); if (parts.Length != 3) continue; records.Add((parts[0], parts[1], parts[2])); } } private ElementReference elementToFocus; protected override async Task OnAfterRenderAsync(bool firstRender) { await JsRuntime.InvokeVoidAsync("BlazorFocusElement", elementToFocus); } private void AddRecord() { records.Add(newRecordInput); newRecordInput = ("", "", ""); } }