2024-05-01 17:13:47 +02:00
|
|
|
@using System.Text.Json
|
2024-03-09 07:07:34 +01:00
|
|
|
@using TaikoWebUI.Pages.Dialogs;
|
2024-05-17 00:32:46 +02:00
|
|
|
@inject Utilities.StringUtil StringUtil;
|
2024-03-09 07:07:34 +01:00
|
|
|
@inject IDialogService DialogService;
|
2024-05-17 00:32:46 +02:00
|
|
|
@inject AuthService AuthService;
|
2024-03-09 07:07:34 +01:00
|
|
|
@inject HttpClient Client
|
|
|
|
@inject NavigationManager NavigationManager
|
|
|
|
|
2024-03-13 15:44:59 +01:00
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (User is not null)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
2024-10-25 01:23:41 +02:00
|
|
|
<MudCard Outlined="true" Class="user-card">
|
2024-03-09 07:07:34 +01:00
|
|
|
<MudCardHeader>
|
|
|
|
<CardHeaderContent>
|
2024-03-09 17:59:21 +01:00
|
|
|
<div style="display:flex;flex-wrap:wrap;align-items:center;gap:5px;">
|
2024-05-26 22:25:24 +02:00
|
|
|
@if (UserSetting is not null)
|
2024-03-09 17:59:21 +01:00
|
|
|
{
|
2024-05-26 22:25:24 +02:00
|
|
|
<MudText Typo="Typo.h6" Style="font-weight:bold;word-break:break-all">@UserSetting?.MyDonName</MudText>
|
2024-03-09 17:59:21 +01:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
<MudSkeleton Width="35%" Height="32px" />
|
|
|
|
}
|
2024-03-09 19:45:20 +01:00
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (AuthService.LoginRequired && User?.IsAdmin == true)
|
2024-03-09 07:46:48 +01:00
|
|
|
{
|
2024-03-09 19:45:20 +01:00
|
|
|
<MudChip Variant="Variant.Outlined" Color="Color.Info" Size="Size.Small" Icon="@Icons.Material.TwoTone.AdminPanelSettings">@Localizer["Admin"]</MudChip>
|
2024-03-09 07:46:48 +01:00
|
|
|
}
|
|
|
|
</div>
|
2024-06-03 03:00:54 +02:00
|
|
|
<MudText Typo="Typo.caption">@Localizer["User ID"]: @User?.Baid</MudText>
|
2024-03-09 07:07:34 +01:00
|
|
|
</CardHeaderContent>
|
|
|
|
<CardHeaderActions>
|
|
|
|
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Dense="true" AnchorOrigin="Origin.BottomLeft"
|
|
|
|
TransformOrigin="Origin.TopLeft" Size="Size.Small">
|
|
|
|
<MudMenuItem Icon="@Icons.Material.Filled.QrCode"
|
2024-05-17 00:32:46 +02:00
|
|
|
OnClick="@(_ => ShowQrCode(User))"
|
|
|
|
OnTouch="@(_ => ShowQrCode(User))"
|
2024-03-09 07:07:34 +01:00
|
|
|
IconColor="@Color.Primary">
|
|
|
|
@Localizer["Show QR Code"]
|
|
|
|
</MudMenuItem>
|
|
|
|
<MudDivider />
|
|
|
|
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
|
2024-05-17 00:32:46 +02:00
|
|
|
Href="@($"Users/{User.Baid}/AccessCode")"
|
2024-03-09 07:07:34 +01:00
|
|
|
IconColor="@Color.Primary">
|
2024-03-27 05:06:10 +01:00
|
|
|
@Localizer["Access Codes"]
|
2024-03-09 07:07:34 +01:00
|
|
|
</MudMenuItem>
|
|
|
|
<MudDivider />
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (AuthService.OnlyAdmin || AuthService.LoginRequired)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
|
|
|
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
|
|
|
|
Href="@($"/ChangePassword")"
|
|
|
|
IconColor="@Color.Primary">
|
|
|
|
@Localizer["Change Password"]
|
|
|
|
</MudMenuItem>
|
|
|
|
<MudDivider />
|
|
|
|
}
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (AuthService.LoginRequired && AuthService.IsAdmin)
|
2024-05-01 17:13:47 +02:00
|
|
|
{
|
|
|
|
<MudMenuItem Icon="@Icons.Material.Filled.Password"
|
2024-05-17 00:32:46 +02:00
|
|
|
OnClick="@(_ => GenerateInviteCode(User.Baid))"
|
|
|
|
OnTouch="@(_ => GenerateInviteCode(User.Baid))"
|
2024-05-01 17:13:47 +02:00
|
|
|
IconColor="@Color.Primary">
|
|
|
|
@Localizer["Generate Invite Code"]
|
|
|
|
</MudMenuItem>
|
|
|
|
<MudDivider />
|
|
|
|
}
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (AuthService.LoginRequired && AuthService.IsAdmin)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
2024-03-09 17:59:21 +01:00
|
|
|
<MudMenuItem Icon="@Icons.Material.Filled.LockReset"
|
2024-05-17 00:32:46 +02:00
|
|
|
OnClick="@(_ => ResetPassword(User))"
|
|
|
|
OnTouch="@(_ => ResetPassword(User))"
|
2024-03-09 07:07:34 +01:00
|
|
|
IconColor="@Color.Primary">
|
2024-03-09 17:59:21 +01:00
|
|
|
@Localizer["Unregister"]
|
2024-03-09 07:07:34 +01:00
|
|
|
</MudMenuItem>
|
|
|
|
<MudDivider />
|
|
|
|
}
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (AuthService.AllowUserDelete)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
|
|
|
<MudMenuItem Icon="@Icons.Material.Filled.Delete"
|
2024-05-17 00:32:46 +02:00
|
|
|
OnClick="@(_ => DeleteUser(User))"
|
|
|
|
OnTouch="@(_ => DeleteUser(User))"
|
2024-03-09 07:07:34 +01:00
|
|
|
IconColor="@Color.Error">
|
|
|
|
@Localizer["Delete User"]
|
|
|
|
</MudMenuItem>
|
|
|
|
}
|
|
|
|
</MudMenu>
|
|
|
|
</CardHeaderActions>
|
|
|
|
</MudCardHeader>
|
|
|
|
<MudCardContent>
|
2024-05-01 17:13:47 +02:00
|
|
|
<MudText Typo="Typo.body2" Style="font-weight:bold">@Localizer["Access Code"]</MudText>
|
2024-03-09 07:07:34 +01:00
|
|
|
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (User.AccessCodes.Count > 0)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
2024-08-09 15:46:55 +02:00
|
|
|
@if (User.AccessCodes[0].Length % 4 == 0 && StringUtil.OnlyHexInString(User.AccessCodes[0]))
|
2024-04-10 02:27:41 +02:00
|
|
|
{
|
2024-08-09 15:46:55 +02:00
|
|
|
foreach (var digitGroup in StringUtil.SplitIntoGroups(User.AccessCodes[0], 4))
|
|
|
|
{
|
|
|
|
<span class="mr-2">@digitGroup</span>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<span class="mr-2">@User.AccessCodes[0]</span>
|
2024-04-10 02:27:41 +02:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
<span class="mr-2">@Localizer["N/A"]</span>
|
|
|
|
}
|
2024-03-09 07:07:34 +01:00
|
|
|
</MudText>
|
2024-05-17 00:32:46 +02:00
|
|
|
@if (User.AccessCodes.Count > 1)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
2024-06-05 03:07:33 +02:00
|
|
|
<MudText Typo="Typo.caption">... @Localizer["And"] @(User.AccessCodes.Count - 1) @Localizer["other access code(s)"]</MudText>
|
2024-05-01 17:13:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Empty line to keep the layout consistent
|
|
|
|
<MudText Typo="Typo.caption"> </MudText>
|
2024-03-09 07:07:34 +01:00
|
|
|
}
|
|
|
|
</MudCardContent>
|
|
|
|
<MudCardActions>
|
|
|
|
<MudStack Row="true" Style="width:100%" Spacing="4" Justify="Justify.FlexEnd">
|
2024-05-17 00:32:46 +02:00
|
|
|
<MudButton Href="@($"Users/{User.Baid}/Profile")"
|
2024-03-09 07:07:34 +01:00
|
|
|
Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Edit"
|
|
|
|
Color="Color.Primary">
|
2024-06-05 16:10:18 +02:00
|
|
|
@Localizer["Edit Profile"]
|
2024-03-09 07:07:34 +01:00
|
|
|
</MudButton>
|
|
|
|
<MudMenu Size="Size.Small"
|
|
|
|
Dense="true"
|
|
|
|
Color="Color.Primary"
|
2024-05-01 17:13:47 +02:00
|
|
|
Label="@Localizer["View Play Data"]"
|
2024-03-10 06:23:47 +01:00
|
|
|
StartIcon="@Icons.Material.Filled.EmojiEvents"
|
2024-03-09 07:07:34 +01:00
|
|
|
EndIcon="@Icons.Material.Filled.KeyboardArrowDown"
|
|
|
|
FullWidth="true"
|
|
|
|
AnchorOrigin="Origin.BottomCenter"
|
|
|
|
TransformOrigin="Origin.TopCenter">
|
2024-05-17 00:32:46 +02:00
|
|
|
<MudMenuItem Href="@($"Users/{User.Baid}/HighScores")">@Localizer["High Scores"]</MudMenuItem>
|
|
|
|
<MudMenuItem Href="@($"Users/{User.Baid}/PlayHistory")">@Localizer["Play History"]</MudMenuItem>
|
|
|
|
<MudMenuItem Href="@($"Users/{User.Baid}/Songs")">@Localizer["Song List"]</MudMenuItem>
|
|
|
|
<MudMenuItem Href="@($"Users/{User.Baid}/DaniDojo")">@Localizer["Dani Dojo"]</MudMenuItem>
|
2024-05-01 17:13:47 +02:00
|
|
|
</MudMenu>
|
|
|
|
</MudStack>
|
|
|
|
</MudCardActions>
|
|
|
|
</MudCard>
|
2024-03-09 07:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@code {
|
2024-05-17 00:32:46 +02:00
|
|
|
[Parameter] public User? User { get; set; }
|
2024-05-26 22:25:24 +02:00
|
|
|
[Parameter] public UserSetting? UserSetting { get; set; }
|
2024-03-09 07:07:34 +01:00
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
2024-05-17 00:32:46 +02:00
|
|
|
{
|
2024-05-26 22:42:50 +02:00
|
|
|
await base.OnInitializedAsync();
|
2024-03-09 07:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private Task ShowQrCode(User user)
|
|
|
|
{
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
{
|
|
|
|
["user"] = user
|
|
|
|
};
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
var options = new DialogOptions { DisableBackdropClick = true };
|
2024-05-01 17:13:47 +02:00
|
|
|
DialogService.Show<UserQrCodeDialog>(Localizer["QR Code"], parameters, options);
|
2024-03-09 07:07:34 +01:00
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task ResetPassword(User user)
|
|
|
|
{
|
2024-05-17 00:32:46 +02:00
|
|
|
var options = new DialogOptions { DisableBackdropClick = true };
|
|
|
|
if (AuthService.LoginRequired && !AuthService.IsAdmin)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-05-01 17:13:47 +02:00
|
|
|
Localizer["Error"],
|
2024-03-09 07:07:34 +01:00
|
|
|
"Only admin can reset password.",
|
2024-05-01 17:13:47 +02:00
|
|
|
Localizer["Dialog OK"], null, null, options);
|
2024-03-09 07:07:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
{
|
|
|
|
["user"] = user
|
|
|
|
};
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
var dialog = await DialogService.ShowAsync<ResetPasswordConfirmDialog>(Localizer["Reset Password"], parameters, options);
|
|
|
|
await dialog.Result;
|
2024-03-09 07:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private async Task DeleteUser(User user)
|
|
|
|
{
|
2024-05-17 00:32:46 +02:00
|
|
|
var options = new DialogOptions { DisableBackdropClick = true };
|
|
|
|
if (!AuthService.AllowUserDelete)
|
2024-03-09 07:07:34 +01:00
|
|
|
{
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-05-01 17:13:47 +02:00
|
|
|
Localizer["Error"],
|
2024-03-09 07:07:34 +01:00
|
|
|
"User deletion is disabled by admin.",
|
2024-05-01 17:13:47 +02:00
|
|
|
Localizer["Dialog OK"], null, null, options);
|
2024-03-09 07:07:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
{
|
|
|
|
["user"] = user
|
|
|
|
};
|
|
|
|
|
2024-10-29 14:33:03 +01:00
|
|
|
var dialog = await DialogService.ShowAsync<UserDeleteConfirmDialog>((string)Localizer["Delete User"], parameters, options);
|
2024-03-09 07:07:34 +01:00
|
|
|
var result = await dialog.Result;
|
|
|
|
|
|
|
|
if (result.Canceled) return;
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
|
|
if (user.Baid == AuthService.GetLoggedInBaid())
|
|
|
|
{
|
|
|
|
await AuthService.Logout();
|
|
|
|
}
|
|
|
|
|
2024-10-29 14:33:03 +01:00
|
|
|
NavigationManager.NavigateTo("/Users", true);
|
2024-03-09 07:07:34 +01:00
|
|
|
}
|
2024-05-01 17:13:47 +02:00
|
|
|
|
|
|
|
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<Dictionary<string, string>>(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
|
|
|
|
};
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
var options = new DialogOptions { DisableBackdropClick = true };
|
|
|
|
await DialogService.ShowAsync<OTPDialog>(Localizer["Invite Code"], parameters, options);
|
2024-05-01 17:13:47 +02:00
|
|
|
}
|
2024-03-09 07:07:34 +01:00
|
|
|
}
|