1
0
mirror of synced 2025-01-30 20:03:46 +01:00

128 lines
4.1 KiB
C#
Raw Normal View History

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