From d487d7a1055a03558acc64e0ec95f21df122c17b Mon Sep 17 00:00:00 2001 From: KIT! Date: Tue, 19 Dec 2023 16:01:13 +0100 Subject: [PATCH 1/2] Fixed Dialogs not being displayed on phones Disable Backdrop Click, you can't close dialogs by clicking on the rest of the window anymore (This is needed to fix Dialogs not showing up on mobile devices) Added OnTouch events --- TaikoWebUI/Pages/Register.razor.cs | 13 +-- TaikoWebUI/Pages/Users.razor | 129 +++++++++++++++-------------- TaikoWebUI/Pages/Users.razor.cs | 29 ++++--- 3 files changed, 91 insertions(+), 80 deletions(-) diff --git a/TaikoWebUI/Pages/Register.razor.cs b/TaikoWebUI/Pages/Register.razor.cs index c7768bb..bbe1550 100644 --- a/TaikoWebUI/Pages/Register.razor.cs +++ b/TaikoWebUI/Pages/Register.razor.cs @@ -26,41 +26,42 @@ public partial class Register if (response != null) { var result = await LoginService.Register(accessCode, inputDateTime, password, confirmPassword, response, Client); + var options = new DialogOptions() { DisableBackdropClick = true }; switch (result) { case 0: await DialogService.ShowMessageBox( "Error", "Only admin can log in.", - "Ok"); + "Ok", null, null, options); NavigationManager.NavigateTo("/Users"); break; case 1: await DialogService.ShowMessageBox( "Success", "Access code registered successfully.", - "Ok"); + "Ok", null, null, options); NavigationManager.NavigateTo("/Users"); break; case 2: await DialogService.ShowMessageBox( "Error", "Confirm password is not the same as password.", - "Ok"); + "Ok", null, null, options); break; case 3: await DialogService.ShowMessageBox( "Error", (MarkupString) "Access code not found.
Please play one game with this access code to register it.", - "Ok"); + "Ok", null, null, options); break; case 4: await DialogService.ShowMessageBox( "Error", (MarkupString) "Access code is already registered, please use set password to login.", - "Ok"); + "Ok", null, null, options); NavigationManager.NavigateTo("/Users"); break; case 5: @@ -68,7 +69,7 @@ public partial class Register "Error", (MarkupString) "Wrong last play time.
If you have forgotten when you last played, please play another game with this access code.", - "Ok"); + "Ok", null, null, options); break; } } diff --git a/TaikoWebUI/Pages/Users.razor b/TaikoWebUI/Pages/Users.razor index 5364138..b69feff 100644 --- a/TaikoWebUI/Pages/Users.razor +++ b/TaikoWebUI/Pages/Users.razor @@ -14,14 +14,14 @@ - - - + + + - - + + @@ -39,38 +39,41 @@ User: @user.Baid - - - - - Show QR Code - - - - Manage Access Codes - - - - Change Password - - - - Reset Password - - @if (LoginService.AllowUserDelete) + + + + + Show QR Code + + + + Manage Access Codes + + + + Change Password + + + + Reset Password + + @if (LoginService.AllowUserDelete) { - + Delete User @@ -81,9 +84,9 @@ Access Code @user.AccessCodes[0] - @if (user.AccessCodes.Count > 1) + @if (user.AccessCodes.Count > 1) { - ... and @(user.AccessCodes.Count-1) other access code(s) + ... and @(user.AccessCodes.Count - 1) other access code(s) } @@ -124,7 +127,7 @@ Login + Label="Access code" /> User: @user.Baid - - - - - Show QR Code - - - - Manage Access Codes - - - - Change Password - - @if (LoginService.AllowUserDelete) + + + + + Show QR Code + + + + Manage Access Codes + + + + Change Password + + @if (LoginService.AllowUserDelete) { - + Delete User @@ -189,9 +194,9 @@ Access Code @user.AccessCodes[0] - @if (user.AccessCodes.Count > 1) + @if (user.AccessCodes.Count > 1) { - ... and @(user.AccessCodes.Count-1) other access code(s) + ... and @(user.AccessCodes.Count - 1) other access code(s) } diff --git a/TaikoWebUI/Pages/Users.razor.cs b/TaikoWebUI/Pages/Users.razor.cs index 8c9441c..6047b78 100644 --- a/TaikoWebUI/Pages/Users.razor.cs +++ b/TaikoWebUI/Pages/Users.razor.cs @@ -1,4 +1,5 @@ -using TaikoWebUI.Pages.Dialogs; +using Microsoft.Extensions.Options; +using TaikoWebUI.Pages.Dialogs; namespace TaikoWebUI.Pages; @@ -17,12 +18,13 @@ public partial class Users private async Task DeleteUser(User user) { + var options = new DialogOptions() { DisableBackdropClick = true }; if (!LoginService.AllowUserDelete) { await DialogService.ShowMessageBox( "Error", "User deletion is disabled by admin.", - "Ok"); + "Ok", null, null, options); return; } var parameters = new DialogParameters @@ -30,7 +32,7 @@ public partial class Users ["user"] = user }; - var dialog = DialogService.Show("Delete User", parameters); + var dialog = DialogService.Show("Delete User", parameters, options); var result = await dialog.Result; if (result.Canceled) return; @@ -41,12 +43,13 @@ public partial class Users private async Task ResetPassword(User user) { - if (!LoginService.IsAdmin) + var options = new DialogOptions() { DisableBackdropClick = true }; + if (LoginService.LoginRequired && !LoginService.IsAdmin) { await DialogService.ShowMessageBox( "Error", "Only admin can reset password.", - "Ok"); + "Ok", null , null, options); return; } var parameters = new DialogParameters @@ -54,7 +57,7 @@ public partial class Users ["user"] = user }; - var dialog = DialogService.Show("Reset Password", parameters); + var dialog = DialogService.Show("Reset Password", parameters, options); var result = await dialog.Result; if (result.Canceled) return; @@ -67,13 +70,14 @@ public partial class Users if (response != null) { var result = LoginService.Login(inputAccessCode, inputPassword, response); + var options = new DialogOptions() { DisableBackdropClick = true }; switch (result) { case 0: await DialogService.ShowMessageBox( "Error", - "Only admin can log in.", - "Ok"); + "Only admin can log in.", + "Ok", null, null, options); await loginForm.ResetAsync(); break; case 1: @@ -83,21 +87,21 @@ public partial class Users await DialogService.ShowMessageBox( "Error", "Wrong password!", - "Ok"); + "Ok", null, null, options); break; case 3: await DialogService.ShowMessageBox( "Error", (MarkupString) "Access code not found.
Please play one game with this access code to register it.", - "Ok"); + "Ok", null, null, options); break; case 4: await DialogService.ShowMessageBox( "Error", (MarkupString) "Access code not registered.
Please use register button to create a password first.", - "Ok"); + "Ok", null, null, options); break; } } @@ -116,7 +120,8 @@ public partial class Users ["user"] = user }; - DialogService.Show("QR Code", parameters); + var options = new DialogOptions() { DisableBackdropClick = true }; + DialogService.Show("QR Code", parameters, options); return Task.CompletedTask; } From e5a85267559be5496bf0349d1871ee0ca83601ea Mon Sep 17 00:00:00 2001 From: KIT! Date: Tue, 19 Dec 2023 16:27:17 +0100 Subject: [PATCH 2/2] Fixed Access Code Binding Admins can now bind codes of other users --- TaikoWebUI/Pages/AccessCode.razor.cs | 9 ++++++++- TaikoWebUI/Services/LoginService.cs | 13 +++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/TaikoWebUI/Pages/AccessCode.razor.cs b/TaikoWebUI/Pages/AccessCode.razor.cs index a01c28a..5ad307f 100644 --- a/TaikoWebUI/Pages/AccessCode.razor.cs +++ b/TaikoWebUI/Pages/AccessCode.razor.cs @@ -67,7 +67,7 @@ public partial class AccessCode { if (response != null) { - var result = await LoginService.BindAccessCode(inputAccessCode, Client); + var result = await LoginService.BindAccessCode(inputAccessCode.ToUpper().Trim(), response.Users.First(u => u.Baid == Baid), Client); switch (result) { case 0: @@ -106,6 +106,13 @@ public partial class AccessCode "Access code cannot be empty.
Please enter a valid access code.", "Ok"); break; + case 5: + await DialogService.ShowMessageBox( + "Error", + (MarkupString) + "You can't do that!
You need to be an admin to edit someone else's access codes.", + "Ok"); + break; } } } diff --git a/TaikoWebUI/Services/LoginService.cs b/TaikoWebUI/Services/LoginService.cs index 94bd83f..ba81dce 100644 --- a/TaikoWebUI/Services/LoginService.cs +++ b/TaikoWebUI/Services/LoginService.cs @@ -152,16 +152,17 @@ public class LoginService if (newLoggedInUser is null) return; LoggedInUser = newLoggedInUser; } - - public async Task BindAccessCode(string inputAccessCode, HttpClient client) + + public async Task BindAccessCode(string inputAccessCode, User user, HttpClient client) { - if (inputAccessCode.Trim() == "") return 4; - if (!IsLoggedIn) return 0; - if (LoggedInUser.AccessCodes.Count >= boundAccessCodeUpperLimit) return 2; + if (inputAccessCode.Trim() == "") return 4; /*Empty access code*/ + if (!IsLoggedIn && LoginRequired) return 0; /*User not connected and login is required*/ + if (LoginRequired && !IsAdmin && !(user.Baid == GetLoggedInUser().Baid)) return 5; /*User not admin trying to update someone elses Access Codes*/ + if (user.AccessCodes.Count >= boundAccessCodeUpperLimit) return 2; /*Limit of codes has been reached*/ var request = new BindAccessCodeRequest { AccessCode = inputAccessCode, - Baid = LoggedInUser.Baid + Baid = user.Baid }; var responseMessage = await client.PostAsJsonAsync("api/Cards", request); return responseMessage.IsSuccessStatusCode ? 1 : 3;