@using System.Text.Json @using TaikoWebUI.Pages.Dialogs; @inject Utilities.StringUtil StringUtil; @inject IDialogService DialogService; @inject AuthService AuthService; @inject HttpClient Client @inject NavigationManager NavigationManager @if (User is not null) { @if (UserSetting is not null) { @UserSetting?.MyDonName } else { } @if (AuthService.LoginRequired && User?.IsAdmin == true) { @Localizer["Admin"] } @Localizer["User ID"]: @User?.Baid @Localizer["Show QR Code"] @Localizer["Access Codes"] @if (AuthService.OnlyAdmin || AuthService.LoginRequired) { @Localizer["Change Password"] } @if (AuthService.LoginRequired && AuthService.IsAdmin) { @Localizer["Generate Invite Code"] } @if (AuthService.LoginRequired && AuthService.IsAdmin) { @Localizer["Unregister"] } @if (AuthService.AllowUserDelete) { @Localizer["Delete User"] } @Localizer["Access Code"] @if (User.AccessCodes.Count > 0) { @if (User.AccessCodes[0].Length % 4 == 0 && StringUtil.OnlyHexInString(User.AccessCodes[0])) { foreach (var digitGroup in StringUtil.SplitIntoGroups(User.AccessCodes[0], 4)) { @digitGroup } } else { @User.AccessCodes[0] } } else { @Localizer["N/A"] } @if (User.AccessCodes.Count > 1) { ... @Localizer["And"] @(User.AccessCodes.Count - 1) @Localizer["other access code(s)"] } else { // Empty line to keep the layout consistent } @Localizer["Edit Profile"] @Localizer["High Scores"] @Localizer["Play History"] @Localizer["Song List"] @Localizer["Dani Dojo"] } @code { [Parameter] public User? User { get; set; } [Parameter] public UserSetting? UserSetting { get; set; } protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); } private Task ShowQrCode(User user) { var parameters = new DialogParameters { ["user"] = user }; var options = new DialogOptions { DisableBackdropClick = true }; DialogService.Show(Localizer["QR Code"], parameters, options); return Task.CompletedTask; } private async Task ResetPassword(User user) { var options = new DialogOptions { DisableBackdropClick = true }; if (AuthService.LoginRequired && !AuthService.IsAdmin) { await DialogService.ShowMessageBox( Localizer["Error"], "Only admin can reset password.", Localizer["Dialog OK"], null, null, options); return; } var parameters = new DialogParameters { ["user"] = user }; var dialog = await DialogService.ShowAsync(Localizer["Reset Password"], parameters, options); await dialog.Result; } private async Task DeleteUser(User user) { var options = new DialogOptions { DisableBackdropClick = true }; if (!AuthService.AllowUserDelete) { await DialogService.ShowMessageBox( Localizer["Error"], "User deletion is disabled by admin.", Localizer["Dialog OK"], null, null, options); return; } var parameters = new DialogParameters { ["user"] = user }; var dialog = await DialogService.ShowAsync((string)Localizer["Delete User"], parameters, options); var result = await dialog.Result; if (result.Canceled) return; if (user.Baid == AuthService.GetLoggedInBaid()) { await AuthService.Logout(); } NavigationManager.NavigateTo("/Users", true); } private async Task GenerateInviteCode(uint baid) { var request = new GenerateOtpRequest { Baid = baid }; var responseMessage = await Client.PostAsJsonAsync("api/Auth/GenerateOtp", request); if (!responseMessage.IsSuccessStatusCode) { await DialogService.ShowMessageBox( Localizer["Error"], Localizer["Unknown Error"], Localizer["Dialog OK"], null, null, new DialogOptions { DisableBackdropClick = true }); return; } var responseContent = await responseMessage.Content.ReadAsStringAsync(); var responseJson = JsonSerializer.Deserialize>(responseContent); if (responseJson == null) { await DialogService.ShowMessageBox( Localizer["Error"], Localizer["Unknown Error"], Localizer["Dialog OK"], null, null, new DialogOptions { DisableBackdropClick = true }); return; } var otp = responseJson["otp"]; var parameters = new DialogParameters { ["otp"] = otp }; var options = new DialogOptions { DisableBackdropClick = true }; await DialogService.ShowAsync(Localizer["Invite Code"], parameters, options); } }