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:
commit
651c2d91f2
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
@ -39,38 +39,41 @@
|
||||
<MudCardHeader>
|
||||
<CardHeaderContent>
|
||||
<MudText Typo="Typo.h6" Style="font-weight:bold">User: @user.Baid</MudText>
|
||||
</CardHeaderContent>
|
||||
<CardHeaderActions>
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Dense="true" AnchorOrigin="Origin.BottomLeft"
|
||||
TransformOrigin="Origin.TopLeft" Size="Size.Small">
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.QrCode"
|
||||
OnClick="@(_ => ShowQrCode(user))"
|
||||
IconColor="@Color.Primary">
|
||||
Show QR Code
|
||||
</MudMenuItem>
|
||||
<MudDivider/>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
|
||||
Href="@($"Users/{user.Baid}/AccessCode")"
|
||||
IconColor="@Color.Primary">
|
||||
Manage Access Codes
|
||||
</MudMenuItem>
|
||||
<MudDivider/>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
|
||||
Href="@($"Users/ChangePassword")"
|
||||
IconColor="@Color.Primary">
|
||||
Change Password
|
||||
</MudMenuItem>
|
||||
<MudDivider/>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.LockReset"
|
||||
OnClick="@(_ => ResetPassword(user))"
|
||||
IconColor="@Color.Primary">
|
||||
Reset Password
|
||||
</MudMenuItem>
|
||||
@if (LoginService.AllowUserDelete)
|
||||
</CardHeaderContent>
|
||||
<CardHeaderActions>
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Dense="true" AnchorOrigin="Origin.BottomLeft"
|
||||
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 />
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
|
||||
Href="@($"Users/{user.Baid}/AccessCode")"
|
||||
IconColor="@Color.Primary">
|
||||
Manage Access Codes
|
||||
</MudMenuItem>
|
||||
<MudDivider />
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
|
||||
Href="@($"Users/ChangePassword")"
|
||||
IconColor="@Color.Primary">
|
||||
Change Password
|
||||
</MudMenuItem>
|
||||
<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>
|
||||
@ -81,9 +84,9 @@
|
||||
<MudCardContent>
|
||||
<MudText Style="font-weight:bold">Access Code</MudText>
|
||||
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">@user.AccessCodes[0]</MudText>
|
||||
@if (user.AccessCodes.Count > 1)
|
||||
@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"
|
||||
@ -153,32 +156,34 @@
|
||||
<MudCardHeader>
|
||||
<CardHeaderContent>
|
||||
<MudText Typo="Typo.h6" Style="font-weight:bold">User: @user.Baid</MudText>
|
||||
</CardHeaderContent>
|
||||
<CardHeaderActions>
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Dense="true" AnchorOrigin="Origin.BottomLeft"
|
||||
TransformOrigin="Origin.TopLeft" Size="Size.Small">
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.QrCode"
|
||||
OnClick="@(_ => ShowQrCode(user))"
|
||||
IconColor="@Color.Primary">
|
||||
Show QR Code
|
||||
</MudMenuItem>
|
||||
<MudDivider/>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
|
||||
Href="@($"Users/{user.Baid}/AccessCode")"
|
||||
IconColor="@Color.Primary">
|
||||
Manage Access Codes
|
||||
</MudMenuItem>
|
||||
<MudDivider/>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
|
||||
Href="@($"Users/ChangePassword")"
|
||||
IconColor="@Color.Primary">
|
||||
Change Password
|
||||
</MudMenuItem>
|
||||
@if (LoginService.AllowUserDelete)
|
||||
</CardHeaderContent>
|
||||
<CardHeaderActions>
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Dense="true" AnchorOrigin="Origin.BottomLeft"
|
||||
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 />
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.FeaturedPlayList"
|
||||
Href="@($"Users/{user.Baid}/AccessCode")"
|
||||
IconColor="@Color.Primary">
|
||||
Manage Access Codes
|
||||
</MudMenuItem>
|
||||
<MudDivider />
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Lock"
|
||||
Href="@($"Users/ChangePassword")"
|
||||
IconColor="@Color.Primary">
|
||||
Change 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>
|
||||
@ -189,9 +194,9 @@
|
||||
<MudCardContent>
|
||||
<MudText Style="font-weight:bold">Access Code</MudText>
|
||||
<MudText Style="font-family:monospace;overflow:hidden;overflow-x:scroll">@user.AccessCodes[0]</MudText>
|
||||
@if (user.AccessCodes.Count > 1)
|
||||
@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>
|
||||
|
@ -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");
|
||||
"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.<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;
|
||||
}
|
||||
|
@ -152,16 +152,17 @@ public class LoginService
|
||||
if (newLoggedInUser is null) return;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user