@using Microsoft.AspNetCore.Components; @using TaikoWebUI.Pages.Dialogs; @inject TaikoWebUI.Utilities.StringUtil StringUtil; @inject IDialogService DialogService; @inject LoginService LoginService; @inject HttpClient Client @inject NavigationManager NavigationManager @if (user is not null) {
@if (userSetting is not null) { @userSetting?.MyDonName } else { } @if (LoginService.LoginRequired && user?.IsAdmin == true) { @Localizer["Admin"] }
User ID: @user?.Baid
@Localizer["Show QR Code"] @Localizer["Manage Access Codes"] @if (LoginService.OnlyAdmin || LoginService.LoginRequired) { @Localizer["Change Password"] } @if (LoginService.LoginRequired && LoginService.IsAdmin) { @Localizer["Unregister"] } @if (LoginService.AllowUserDelete) { @Localizer["Delete User"] }
Access Code @foreach (var digitGroup in StringUtil.SplitIntoGroups(user.AccessCodes[0], 4)) { @digitGroup } @if (user.AccessCodes.Count > 1) { ... and @(user.AccessCodes.Count - 1) other access code(s) } @Localizer["edit profile"] @Localizer["high scores"] @Localizer["dani dojo"]
} @code { [Parameter] public User? user { get; set; } private DashboardResponse? response; private UserSetting? userSetting; protected override async Task OnInitializedAsync() { if (user is not null) { userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{user.Baid}"); } } private Task ShowQrCode(User user) { var parameters = new DialogParameters { ["user"] = user }; var options = new DialogOptions() { DisableBackdropClick = true }; DialogService.Show("QR Code", parameters, options); return Task.CompletedTask; } private async Task ResetPassword(User user) { var options = new DialogOptions() { DisableBackdropClick = true }; if (LoginService.LoginRequired && !LoginService.IsAdmin) { await DialogService.ShowMessageBox( "Error", "Only admin can reset password.", "Ok", null, null, options); return; } var parameters = new DialogParameters { ["user"] = user }; var dialog = DialogService.Show("Reset Password", parameters, options); var result = await dialog.Result; if (result.Canceled) return; response = await Client.GetFromJsonAsync("api/Dashboard"); } private async Task DeleteUser(User user) { var options = new DialogOptions() { DisableBackdropClick = true }; if (!LoginService.AllowUserDelete) { await DialogService.ShowMessageBox( "Error", "User deletion is disabled by admin.", "Ok", null, null, options); return; } var parameters = new DialogParameters { ["user"] = user }; var dialog = DialogService.Show("Delete User", parameters, options); var result = await dialog.Result; if (result.Canceled) return; response = await Client.GetFromJsonAsync("api/Dashboard"); LoginService.Logout(); NavigationManager.NavigateTo("/Users"); } }