1
0
mirror of synced 2024-11-28 08:30:56 +01:00

Merge pull request #25 from AkaiiKitsune/Mobile-UI-Fixes

Fixed dialogs not being displayed on phone and tweaked access code binding
This commit is contained in:
S-Sebb?? 2023-12-19 16:49:48 +00:00 committed by GitHub
commit 651c2d91f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 87 deletions

View File

@ -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.<br />Please enter a valid access code.",
"Ok");
break;
case 5:
await DialogService.ShowMessageBox(
"Error",
(MarkupString)
"You can't do that!<br />You need to be an admin to edit someone else's access codes.",
"Ok");
break;
}
}
}

View File

@ -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.<br />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.<br />If you have forgotten when you last played, please play another game with this access code.",
"Ok");
"Ok", null, null, options);
break;
}
}

View File

@ -14,14 +14,14 @@
<MudItem xs="12" md="6" lg="4">
<MudCard Outlined="true">
<MudCardContent>
<MudSkeleton Width="30%" Height="42px;" Class="mb-5"/>
<MudSkeleton Width="80%"/>
<MudSkeleton Width="100%"/>
<MudSkeleton Width="30%" Height="42px;" Class="mb-5" />
<MudSkeleton Width="80%" />
<MudSkeleton Width="100%" />
</MudCardContent>
<MudCardActions>
<MudStack Row="true" Style="width:100%" Spacing="4" Justify="Justify.FlexEnd">
<MudSkeleton Width="64px" Height="40px"/>
<MudSkeleton Width="64px" Height="40px"/>
<MudSkeleton Width="64px" Height="40px" />
<MudSkeleton Width="64px" Height="40px" />
</MudStack>
</MudCardActions>
</MudCard>
@ -45,32 +45,35 @@
TransformOrigin="Origin.TopLeft" Size="Size.Small">
<MudMenuItem Icon="@Icons.Material.Filled.QrCode"
OnClick="@(_ => ShowQrCode(user))"
OnTouch="@(_ => ShowQrCode(user))"
IconColor="@Color.Primary">
Show QR Code
</MudMenuItem>
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
Href="@($"Users/{user.Baid}/AccessCode")"
IconColor="@Color.Primary">
Manage Access Codes
</MudMenuItem>
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
Href="@($"Users/ChangePassword")"
IconColor="@Color.Primary">
Change Password
</MudMenuItem>
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.LockReset"
OnClick="@(_ => ResetPassword(user))"
OnTouch="@(_ => ResetPassword(user))"
IconColor="@Color.Primary">
Reset Password
</MudMenuItem>
@if (LoginService.AllowUserDelete)
{
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.Delete"
OnClick="@(_ => DeleteUser(user))"
OnTouch="@(_ => DeleteUser(user))"
IconColor="@Color.Error">
Delete User
</MudMenuItem>
@ -83,7 +86,7 @@
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">@user.AccessCodes[0]</MudText>
@if (user.AccessCodes.Count > 1)
{
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">... and @(user.AccessCodes.Count-1) other access code(s)</MudText>
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">... and @(user.AccessCodes.Count - 1) other access code(s)</MudText>
}
</MudCardContent>
<MudCardActions>
@ -124,7 +127,7 @@
<MudText Typo="Typo.h4" Align="Align.Center">Login</MudText>
<MudTextField @bind-value="inputAccessCode" InputType="InputType.Text" T="string"
FullWidth="true" Required="@true" RequiredError="Access code is required"
Label="Access code"/>
Label="Access code" />
<MudTextField @bind-Value="inputPassword" InputType="InputType.Password"
T="string" FullWidth="true" Required="@true"
RequiredError="Password is required"
@ -159,16 +162,17 @@
TransformOrigin="Origin.TopLeft" Size="Size.Small">
<MudMenuItem Icon="@Icons.Material.Filled.QrCode"
OnClick="@(_ => ShowQrCode(user))"
OnTouch="@(_ => ShowQrCode(user))"
IconColor="@Color.Primary">
Show QR Code
</MudMenuItem>
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
Href="@($"Users/{user.Baid}/AccessCode")"
IconColor="@Color.Primary">
Manage Access Codes
</MudMenuItem>
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
Href="@($"Users/ChangePassword")"
IconColor="@Color.Primary">
@ -176,9 +180,10 @@
</MudMenuItem>
@if (LoginService.AllowUserDelete)
{
<MudDivider/>
<MudDivider />
<MudMenuItem Icon="@Icons.Material.Filled.Delete"
OnClick="@(_ => DeleteUser(user))"
OnTouch="@(_ => DeleteUser(user))"
IconColor="@Color.Error">
Delete User
</MudMenuItem>
@ -191,7 +196,7 @@
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">@user.AccessCodes[0]</MudText>
@if (user.AccessCodes.Count > 1)
{
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">... and @(user.AccessCodes.Count-1) other access code(s)</MudText>
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">... and @(user.AccessCodes.Count - 1) other access code(s)</MudText>
}
</MudCardContent>
<MudCardActions>

View File

@ -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<UserDeleteConfirmDialog>("Delete User", parameters);
var dialog = DialogService.Show<UserDeleteConfirmDialog>("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<ResetPasswordConfirmDialog>("Reset Password", parameters);
var dialog = DialogService.Show<ResetPasswordConfirmDialog>("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");
"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.<br />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.<br />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<UserQrCodeDialog>("QR Code", parameters);
var options = new DialogOptions() { DisableBackdropClick = true };
DialogService.Show<UserQrCodeDialog>("QR Code", parameters, options);
return Task.CompletedTask;
}

View File

@ -153,15 +153,16 @@ public class LoginService
LoggedInUser = newLoggedInUser;
}
public async Task<int> BindAccessCode(string inputAccessCode, HttpClient client)
public async Task<int> 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;