2023-06-08 21:34:59 +00:00
|
|
|
@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>
|
2023-06-09 07:45:14 +00:00
|
|
|
@if (msg != null)
|
|
|
|
{
|
|
|
|
<span>@msg</span>
|
|
|
|
}
|
2023-06-08 21:34:59 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
private string Password { get; set; }
|
|
|
|
|
2023-06-09 07:45:14 +00:00
|
|
|
private string msg { get; set; }
|
|
|
|
|
2023-06-08 21:34:59 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public string userid { get; set; }
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public string hash { get; set; }
|
|
|
|
|
|
|
|
public async void reset()
|
|
|
|
{
|
2023-06-09 07:45:14 +00:00
|
|
|
if (!int.TryParse(userid, out _))
|
2023-06-12 10:11:48 +00:00
|
|
|
{
|
|
|
|
msg = "malformed userid.";
|
2023-06-08 21:34:59 +00:00
|
|
|
return;
|
2023-06-12 10:11:48 +00:00
|
|
|
}
|
|
|
|
Console.WriteLine("Resetting a password...");
|
2023-06-08 21:34:59 +00:00
|
|
|
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
|
|
|
|
if (user == null)
|
2023-06-12 10:11:48 +00:00
|
|
|
{
|
|
|
|
msg = "This user does not exist.";
|
2023-06-08 21:34:59 +00:00
|
|
|
return;
|
2023-06-12 10:11:48 +00:00
|
|
|
}
|
2023-06-08 21:34:59 +00:00
|
|
|
if (user.ResetPasswordToken != hash)
|
|
|
|
{
|
2023-06-12 10:11:48 +00:00
|
|
|
msg = "The token does not match the account.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (user.ResetPasswordExpiresAt == -1 || user.ResetPasswordToken == "-1")
|
|
|
|
{
|
|
|
|
msg = "There is currently no valid link to reset this accounts password.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (user.ResetPasswordExpiresAt < DateTimeOffset.Now.ToUnixTimeMilliseconds())
|
|
|
|
{
|
|
|
|
msg = "This link has expired.";
|
2023-06-08 21:34:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user.Password = Password = BCrypt.Net.BCrypt.HashPassword(Password);
|
2023-06-09 07:45:14 +00:00
|
|
|
user.ResetPasswordToken = "-1";
|
2023-06-12 10:11:48 +00:00
|
|
|
user.ResetPasswordExpiresAt = -1;
|
2023-06-08 21:34:59 +00:00
|
|
|
|
|
|
|
await UsersRepository.updateUserAsync(user);
|
2023-06-09 07:45:14 +00:00
|
|
|
|
|
|
|
msg = "Your Password has been updated.";
|
|
|
|
|
2023-06-08 21:34:59 +00:00
|
|
|
}
|
|
|
|
}
|