bulletboards/ImageBoardServerApp/Pages/Accounts/ClickOn/ClickOnReset.razor
limited_dev e8e97b2cd9 feat: finished email confirmation, finished Password Reset
!fix: The user auth system now uses the id, not the email

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
2023-06-09 09:45:14 +02:00

60 lines
No EOL
1.5 KiB
Text

@page "/sys/click/resetpw/{userid}/{hash}"
@using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data.Repository
@inject AuthenticationStateProvider authStateProvider
@inject NavigationManager navManager
<PageTitle>Password reset</PageTitle>
<span>Password reset for account id #@userid</span>
<div class="login">
<form>
<RadzenFormField Text="New Password" Variant="Variant.Outlined">
<RadzenPassword @bind-Value="@Password" />
</RadzenFormField>
<br/>
<br/>
<RadzenButton Click=@reset Text="reset" ButtonStyle="ButtonStyle.Secondary" />
<br/>
</form>
@if (msg != null)
{
<span>@msg</span>
}
</div>
@code {
private string Password { get; set; }
private string msg { get; set; }
[Parameter]
[Required]
public string userid { get; set; }
[Parameter]
[Required]
public string hash { get; set; }
public async void reset()
{
if (!int.TryParse(userid, out _))
return;
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
if (user == null)
return;
if (user.ResetPasswordToken != hash)
{
return;
}
Console.WriteLine("Resetting a password...");
user.Password = Password = BCrypt.Net.BCrypt.HashPassword(Password);
user.ResetPasswordToken = "-1";
await UsersRepository.updateUserAsync(user);
msg = "Your Password has been updated.";
}
}