Implemented reset password button if logged in as admin user
This commit is contained in:
parent
4ab41ea9f3
commit
e3d78b80d5
23
TaikoWebUI/Pages/Dialogs/ResetPasswordConfirmDialog.razor
Normal file
23
TaikoWebUI/Pages/Dialogs/ResetPasswordConfirmDialog.razor
Normal 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>
|
34
TaikoWebUI/Pages/Dialogs/ResetPasswordConfirmDialog.razor.cs
Normal file
34
TaikoWebUI/Pages/Dialogs/ResetPasswordConfirmDialog.razor.cs
Normal 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));
|
||||
}
|
||||
}
|
@ -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/>
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user