|
@@ -1,6 +1,11 @@
|
|
-@implements IDisposable
|
|
|
|
|
|
+@using Microsoft.AspNetCore.Identity
|
|
|
|
+@using Microsoft.AspNetCore.Components.Authorization
|
|
|
|
+@implements IDisposable
|
|
|
|
|
|
@inject NavigationManager NavigationManager
|
|
@inject NavigationManager NavigationManager
|
|
|
|
+@inject UserManager<ApplicationUser> _userManager
|
|
|
|
+@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
|
|
+
|
|
|
|
|
|
<div style="padding: 2em;"><img src="/img/agehab.svg" class="img-fluid" /></div>
|
|
<div style="padding: 2em;"><img src="/img/agehab.svg" class="img-fluid" /></div>
|
|
|
|
|
|
@@ -35,15 +40,16 @@
|
|
</form>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
- @* <div class="nav-item px-3">
|
|
|
|
- <form action="Account/ResetPassword" method="post">
|
|
|
|
|
|
+ <div class="nav-item px-3">
|
|
|
|
+ <form action="Account/ResetPassword" method="get">
|
|
<AntiforgeryToken />
|
|
<AntiforgeryToken />
|
|
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
|
|
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
|
|
|
|
+ <input type="hidden" name="code" value="@encodedCode" />
|
|
<button type="submit" class="nav-link">
|
|
<button type="submit" class="nav-link">
|
|
<span class="bi bi-arrow-bar-left-nav-menu" aria-hidden="true"></span> Trocar Senha
|
|
<span class="bi bi-arrow-bar-left-nav-menu" aria-hidden="true"></span> Trocar Senha
|
|
</button>
|
|
</button>
|
|
</form>
|
|
</form>
|
|
- </div> *@
|
|
|
|
|
|
+ </div>
|
|
|
|
|
|
</Authorized>
|
|
</Authorized>
|
|
<NotAuthorized>
|
|
<NotAuthorized>
|
|
@@ -74,22 +80,55 @@
|
|
|
|
|
|
@code {
|
|
@code {
|
|
private string? currentUrl;
|
|
private string? currentUrl;
|
|
|
|
+ private string encodedCode = string.Empty;
|
|
|
|
+ private string? userEmail;
|
|
|
|
|
|
- protected override void OnInitialized()
|
|
|
|
|
|
+
|
|
|
|
+ protected override async Task OnInitializedAsync()
|
|
{
|
|
{
|
|
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
|
|
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
|
|
NavigationManager.LocationChanged += OnLocationChanged;
|
|
NavigationManager.LocationChanged += OnLocationChanged;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Obter usuário autenticado.
|
|
|
|
+ var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
|
|
+ var user = authState.User;
|
|
|
|
+
|
|
|
|
+ if (user.Identity?.IsAuthenticated == true)
|
|
|
|
+ {
|
|
|
|
+ userEmail = user.FindFirst(c => c.Type == System.Security.Claims.ClaimTypes.Email)?.Value;
|
|
|
|
+
|
|
|
|
+ // Gerar código para o usuário autenticado.
|
|
|
|
+ encodedCode = await GenerateResetCodeAsync(userEmail);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private async Task<string> GenerateResetCodeAsync(string? email)
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrEmpty(email))
|
|
|
|
+ return string.Empty;
|
|
|
|
+
|
|
|
|
+ var user = await _userManager.FindByEmailAsync(email);
|
|
|
|
+ if (user == null)
|
|
|
|
+ return string.Empty;
|
|
|
|
+
|
|
|
|
+ var code = await _userManager.GeneratePasswordResetTokenAsync(user);
|
|
|
|
+
|
|
|
|
+ return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(code));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
{
|
|
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
|
|
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
|
|
StateHasChanged();
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
public void Dispose()
|
|
public void Dispose()
|
|
{
|
|
{
|
|
NavigationManager.LocationChanged -= OnLocationChanged;
|
|
NavigationManager.LocationChanged -= OnLocationChanged;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|