@page "/account/reset-password" @layout AuthenticationLayout @using Indotalent.Shared.Consts @using Microsoft.JSInterop @inject IJSRuntime JSRuntime @inject ISnackbar Snackbar @inject NavigationManager Navigation Reset Password - @GlobalConsts.AppInitial
New Password
Confirm New Password
@if (isProcessing) { Resetting... } else { Reset Password }
@code { [SupplyParameterFromQuery] public string? userId { get; set; } [SupplyParameterFromQuery] public string? code { get; set; } private MudForm form = default!; private bool success; private bool isProcessing; private bool showPassword; private ResetModel model = new(); private class ResetModel { public string NewPassword { get; set; } = ""; public string ConfirmPassword { get; set; } = ""; } private string? PasswordMatch(string arg) { if (model.NewPassword != arg) return "Passwords do not match"; return null; } private async Task HandleResetPassword() { await form.Validate(); if (!success) return; if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(code)) { Snackbar.Add("Invalid reset token or user ID.", Severity.Error); return; } isProcessing = true; StateHasChanged(); var result = await JSRuntime.InvokeAsync("apiResetPassword", userId, code, model.NewPassword); if (result.Status == 200) { Snackbar.Add("Password reset successful! You can now sign in.", Severity.Success); await Task.Delay(500); Navigation.NavigateTo("/account/login"); } else { Snackbar.Add(result.Title ?? "Failed to reset password", Severity.Error); } isProcessing = false; StateHasChanged(); } private class ApiResponse { public int Status { get; set; } public string? Title { get; set; } } }