@namespace Oqtane.Modules.Admin.Reset @inherits ModuleBase @inject NavigationManager NavigationManager @inject IUserService UserService
@code { private string _username = string.Empty; private string _password = string.Empty; private string _confirm = string.Empty; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous; protected override void OnInitialized() { if (PageState.QueryString.ContainsKey("name") && PageState.QueryString.ContainsKey("token")) { _username = PageState.QueryString["name"]; } else { NavigationManager.NavigateTo(NavigateUrl(string.Empty)); } } private async Task Reset() { try { if (_username != string.Empty && _password != string.Empty && _confirm != string.Empty) { if (_password == _confirm) { var user = new User { SiteId = PageState.Site.SiteId, Username = _username, Password = _password }; user = await UserService.ResetPasswordAsync(user, PageState.QueryString["token"]); if (user != null) { await logger.LogInformation("User Password Reset {Username}", _username); NavigationManager.NavigateTo(NavigateUrl("login")); } else { await logger.LogError("Error Resetting User Password {Username}", _username); AddModuleMessage("Error Resetting User Password. Please Ensure Password Meets Complexity Requirements.", MessageType.Error); } } else { AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning); } } else { AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Resetting User Password {Username} {Error}", _username, ex.Message); AddModuleMessage("Error Resetting User Password", MessageType.Error); } } private void Cancel() { NavigationManager.NavigateTo(NavigateUrl(string.Empty)); } }