2022-09-11 18:33:58 +02:00
|
|
|
|
using TaikoWebUI.Pages.Dialogs;
|
|
|
|
|
|
|
|
|
|
namespace TaikoWebUI.Pages;
|
|
|
|
|
|
2023-11-11 22:04:11 +01:00
|
|
|
|
public partial class Users
|
2022-09-11 18:33:58 +02:00
|
|
|
|
{
|
2023-11-12 18:56:57 +01:00
|
|
|
|
private string inputAccessCode = "";
|
2023-10-16 11:38:27 +02:00
|
|
|
|
private MudForm loginForm = default!;
|
2023-11-12 18:56:57 +01:00
|
|
|
|
private string inputPassword = "";
|
2022-09-11 18:33:58 +02:00
|
|
|
|
private DashboardResponse? response;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-11 22:04:11 +01:00
|
|
|
|
private async Task DeleteUser(User user)
|
2022-09-11 18:33:58 +02:00
|
|
|
|
{
|
2023-11-13 00:12:54 +01:00
|
|
|
|
if (!LoginService.AllowUserDelete)
|
|
|
|
|
{
|
|
|
|
|
await DialogService.ShowMessageBox(
|
|
|
|
|
"Error",
|
|
|
|
|
"User deletion is disabled by admin.",
|
|
|
|
|
"Ok");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-11 18:33:58 +02:00
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
|
{
|
|
|
|
|
["user"] = user
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-11 22:04:11 +01:00
|
|
|
|
var dialog = DialogService.Show<UserDeleteConfirmDialog>("Delete User", parameters);
|
2022-09-11 18:33:58 +02:00
|
|
|
|
var result = await dialog.Result;
|
|
|
|
|
|
2023-10-21 13:33:00 +02:00
|
|
|
|
if (result.Canceled) return;
|
2023-09-09 14:58:20 +02:00
|
|
|
|
|
|
|
|
|
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
|
2023-11-11 22:04:11 +01:00
|
|
|
|
OnLogout();
|
2023-09-09 14:58:20 +02:00
|
|
|
|
}
|
2023-10-16 11:38:27 +02:00
|
|
|
|
|
|
|
|
|
private async Task OnLogin()
|
|
|
|
|
{
|
|
|
|
|
if (response != null)
|
2022-09-11 18:33:58 +02:00
|
|
|
|
{
|
2023-11-12 18:56:57 +01:00
|
|
|
|
var result = LoginService.Login(inputAccessCode, inputPassword, response);
|
2023-10-16 11:38:27 +02:00
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
|
|
|
|
"Error",
|
|
|
|
|
"Only admin can log in.",
|
|
|
|
|
"Ok");
|
2023-10-21 13:33:00 +02:00
|
|
|
|
await loginForm.ResetAsync();
|
2023-10-16 11:38:27 +02:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2023-11-11 22:04:11 +01:00
|
|
|
|
NavigationManager.NavigateTo("/Users");
|
2023-10-16 11:38:27 +02:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
|
|
|
|
"Error",
|
|
|
|
|
"Wrong password!",
|
|
|
|
|
"Ok");
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
|
|
|
|
"Error",
|
|
|
|
|
(MarkupString)
|
2023-11-12 18:56:57 +01:00
|
|
|
|
"Access code not found.<br />Please play one game with this access code to register it.",
|
2023-10-16 11:38:27 +02:00
|
|
|
|
"Ok");
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
await DialogService.ShowMessageBox(
|
|
|
|
|
"Error",
|
|
|
|
|
(MarkupString)
|
2023-11-12 18:56:57 +01:00
|
|
|
|
"Access code not registered.<br />Please use register button to create a password first.",
|
2023-10-16 11:38:27 +02:00
|
|
|
|
"Ok");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-11 18:33:58 +02:00
|
|
|
|
}
|
2023-10-16 11:38:27 +02:00
|
|
|
|
}
|
2022-09-11 18:33:58 +02:00
|
|
|
|
|
2023-10-16 11:38:27 +02:00
|
|
|
|
private void OnLogout()
|
|
|
|
|
{
|
|
|
|
|
LoginService.Logout();
|
2023-11-11 22:04:11 +01:00
|
|
|
|
NavigationManager.NavigateTo("/Users");
|
2022-09-11 18:33:58 +02:00
|
|
|
|
}
|
2023-10-16 11:38:27 +02:00
|
|
|
|
|
2023-10-01 14:09:04 +02:00
|
|
|
|
private Task ShowQrCode(User user)
|
|
|
|
|
{
|
|
|
|
|
var parameters = new DialogParameters
|
|
|
|
|
{
|
|
|
|
|
["user"] = user
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DialogService.Show<UserQrCodeDialog>("QR Code", parameters);
|
2022-09-11 18:33:58 +02:00
|
|
|
|
|
2023-10-01 14:09:04 +02:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2022-09-11 18:33:58 +02:00
|
|
|
|
}
|