2024-03-09 17:59:21 +01:00
|
|
|
|
using TaikoWebUI.Pages.Dialogs;
|
2023-11-12 18:56:57 +01:00
|
|
|
|
|
|
|
|
|
namespace TaikoWebUI.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class AccessCode
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Baid { get; set; }
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
private string inputAccessCode = "";
|
|
|
|
|
private MudForm bindAccessCodeForm = default!;
|
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
private User? User { get; set; }
|
|
|
|
|
|
2024-03-09 17:59:21 +01:00
|
|
|
|
private UserSetting? userSetting;
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2024-03-09 17:59:21 +01:00
|
|
|
|
private readonly List<BreadcrumbItem> breadcrumbs = new();
|
2023-11-12 18:56:57 +01:00
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
2024-05-25 19:12:30 +02:00
|
|
|
|
|
|
|
|
|
if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
|
|
|
|
|
{
|
|
|
|
|
await AuthService.LoginWithAuthToken();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
await InitializeUser();
|
2024-03-09 17:59:21 +01:00
|
|
|
|
|
|
|
|
|
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
|
2024-03-09 17:59:21 +01:00
|
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
|
2024-03-09 17:59:21 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
|
2024-05-17 00:32:46 +02:00
|
|
|
|
}
|
2024-03-09 17:59:21 +01:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
|
2024-05-01 17:13:47 +02:00
|
|
|
|
breadcrumbs.Add(new BreadcrumbItem(Localizer["Access Codes"], href: $"/Users/{Baid}/AccessCode", disabled: false));
|
2023-11-12 18:56:57 +01:00
|
|
|
|
}
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
private async Task InitializeUser()
|
|
|
|
|
{
|
2024-06-05 17:58:07 +02:00
|
|
|
|
User = await Client.GetFromJsonAsync<User>($"api/Users/{Baid}");
|
2023-11-12 18:56:57 +01:00
|
|
|
|
}
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
private async Task DeleteAccessCode(string accessCode)
|
|
|
|
|
{
|
|
|
|
|
var parameters = new DialogParameters<AccessCodeDeleteConfirmDialog>
|
|
|
|
|
{
|
|
|
|
|
{ x => x.User, User },
|
|
|
|
|
{ x => x.AccessCode, accessCode }
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
var dialog = await DialogService.ShowAsync<AccessCodeDeleteConfirmDialog>("Delete Access Code", parameters);
|
2023-11-12 18:56:57 +01:00
|
|
|
|
var result = await dialog.Result;
|
|
|
|
|
|
|
|
|
|
if (result.Canceled) return;
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
await InitializeUser();
|
|
|
|
|
NavigationManager.NavigateTo(NavigationManager.Uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnBind()
|
|
|
|
|
{
|
2024-05-17 00:32:46 +02:00
|
|
|
|
if (User == null) return;
|
|
|
|
|
var result = await AuthService.BindAccessCode(inputAccessCode.ToUpper().Trim(), User);
|
|
|
|
|
switch (result)
|
2023-11-12 18:56:57 +01:00
|
|
|
|
{
|
2024-05-17 00:32:46 +02:00
|
|
|
|
case 0:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Localizer["Error"],
|
2024-05-17 00:32:46 +02:00
|
|
|
|
(MarkupString)
|
2024-06-05 03:07:33 +02:00
|
|
|
|
(string)Localizer["Not Logged In Error"],
|
|
|
|
|
Localizer["Dialog OK"]);
|
2024-05-17 00:32:46 +02:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Localizer["Success"],
|
|
|
|
|
(MarkupString)
|
|
|
|
|
(string)Localizer["Access Code Bound Success"],
|
|
|
|
|
Localizer["Dialog OK"]);
|
2024-05-17 00:32:46 +02:00
|
|
|
|
await InitializeUser();
|
|
|
|
|
NavigationManager.NavigateTo(NavigationManager.Uri);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Localizer["Error"],
|
2024-05-17 00:32:46 +02:00
|
|
|
|
(MarkupString)
|
2024-06-05 03:07:33 +02:00
|
|
|
|
(string)Localizer["Access Code Upper Limit Error"],
|
|
|
|
|
Localizer["Dialog OK"]);
|
2024-05-17 00:32:46 +02:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Localizer["Error"],
|
2024-05-17 00:32:46 +02:00
|
|
|
|
(MarkupString)
|
2024-06-05 03:07:33 +02:00
|
|
|
|
(string)Localizer["Access Code Already Bound Error"],
|
|
|
|
|
Localizer["Dialog OK"]);
|
2024-05-17 00:32:46 +02:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Localizer["Error"],
|
2024-05-17 00:32:46 +02:00
|
|
|
|
(MarkupString)
|
2024-06-05 03:07:33 +02:00
|
|
|
|
(string)Localizer["Access Code Empty Error"],
|
|
|
|
|
Localizer["Dialog OK"]);
|
2024-05-17 00:32:46 +02:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Localizer["Error"],
|
2024-05-17 00:32:46 +02:00
|
|
|
|
(MarkupString)
|
2024-06-05 03:07:33 +02:00
|
|
|
|
(string)Localizer["Access Code Not Admin Error"],
|
|
|
|
|
Localizer["Dialog OK"]);
|
2024-05-17 00:32:46 +02:00
|
|
|
|
break;
|
2023-11-12 18:56:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|