1
0
mirror of synced 2025-02-17 19:19:18 +01:00

Implemented reset password button if logged in as admin user

This commit is contained in:
S-Sebb 2023-12-19 00:12:48 +00:00
parent 4ab41ea9f3
commit e3d78b80d5
4 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,23 @@
@inject HttpClient Client
@inject ISnackbar Snackbar
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.LockReset" Class="mr-2" />
Reset user's password?
</MudText>
</TitleContent>
<DialogContent>
<MudText>
Do you really want to reset user <b>@User.Baid</b>'s password?<br />
This will remove the user's current password and user will have to register again.
</MudText>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">CANCEL</MudButton>
<MudButton Color="Color.Error" OnClick="ResetPassword">
<MudText>RESET</MudText>
</MudButton>
</DialogActions>
</MudDialog>

View File

@ -0,0 +1,34 @@
namespace TaikoWebUI.Pages.Dialogs;
public partial class ResetPasswordConfirmDialog
{
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public User User { get; set; } = new();
private void Cancel() => MudDialog.Cancel();
private async Task ResetPassword()
{
var request = new SetPasswordRequest
{
Baid = User.Baid,
Password = "",
Salt = ""
};
var responseMessage = await Client.PostAsJsonAsync("api/Credentials", request);
if (!responseMessage.IsSuccessStatusCode)
{
Snackbar.Add("Something went wrong when resetting password!", Severity.Error);
MudDialog.Close(DialogResult.Ok(false));
return;
}
Snackbar.Add("Reset password success!", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}

View File

@ -60,6 +60,12 @@
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)
{
<MudDivider/>

View File

@ -38,6 +38,29 @@ public partial class Users
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
OnLogout();
}
private async Task ResetPassword(User user)
{
if (!LoginService.IsAdmin)
{
await DialogService.ShowMessageBox(
"Error",
"Only admin can reset password.",
"Ok");
return;
}
var parameters = new DialogParameters
{
["user"] = user
};
var dialog = DialogService.Show<ResetPasswordConfirmDialog>("Reset Password", parameters);
var result = await dialog.Result;
if (result.Canceled) return;
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
}
private async Task OnLogin()
{