1
0
mirror of synced 2024-12-23 20:04:52 +01:00
TaikoLocalServer/TaikoWebUI/Pages/Users.razor.cs

100 lines
2.9 KiB
C#
Raw Normal View History

2022-09-11 18:33:58 +02:00
using TaikoWebUI.Pages.Dialogs;
namespace TaikoWebUI.Pages;
public partial class Users
2022-09-11 18:33:58 +02:00
{
private string inputAccessCode = "";
2023-10-16 11:38:27 +02:00
private MudForm loginForm = default!;
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");
}
private async Task DeleteUser(User user)
2022-09-11 18:33:58 +02: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
};
var dialog = DialogService.Show<UserDeleteConfirmDialog>("Delete User", parameters);
2022-09-11 18:33:58 +02:00
var result = await dialog.Result;
if (result.Canceled) return;
2023-09-09 14:58:20 +02:00
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
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
{
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");
await loginForm.ResetAsync();
2023-10-16 11:38:27 +02:00
break;
case 1:
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)
"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)
"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();
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
}