2023-06-08 21:34:59 +00:00
|
|
|
@page "/sys/resetpw"
|
|
|
|
@using ImageBoardServerApp.Data.Repository
|
|
|
|
@using ImageBoardServerApp.Util
|
|
|
|
<h3 class="headLogin">Reset your Password</h3>
|
|
|
|
|
|
|
|
<div class="login">
|
|
|
|
<form>
|
|
|
|
<RadzenFormField Text="Email" Variant="Variant.Outlined">
|
2023-06-12 18:46:44 +00:00
|
|
|
<RadzenTextBox @bind-Value="@Email"/>
|
2023-06-08 21:34:59 +00:00
|
|
|
</RadzenFormField>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
2023-06-12 19:22:44 +00:00
|
|
|
<RadzenButton Click=@resetPassword Text="Send reset email" ButtonStyle="ButtonStyle.Secondary"/>
|
2023-06-08 21:34:59 +00:00
|
|
|
<br/>
|
|
|
|
</form>
|
|
|
|
@if (msg != null)
|
|
|
|
{
|
|
|
|
<div>
|
|
|
|
<span class="msg">@msg</span>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
private string Email { get; set; }
|
|
|
|
private string msg { get; set; }
|
|
|
|
|
|
|
|
private async void resetPassword()
|
|
|
|
{
|
2023-06-12 10:27:27 +00:00
|
|
|
msg = "Checking...";
|
2023-06-08 21:34:59 +00:00
|
|
|
var user = await UsersRepository.getUserByEmailRawAsync(Email);
|
|
|
|
if (user == null)
|
|
|
|
{
|
2023-06-12 10:27:27 +00:00
|
|
|
msg = "This user is not registered.";
|
2023-06-08 21:34:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-06-12 10:27:27 +00:00
|
|
|
Console.WriteLine("Resetting a password...");
|
2023-06-08 21:34:59 +00:00
|
|
|
|
2023-06-12 10:27:27 +00:00
|
|
|
msg = "Generating";
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-06-08 21:34:59 +00:00
|
|
|
var hash = TheManager.getmd5Hash();
|
|
|
|
user.ResetPasswordToken = hash;
|
|
|
|
user.ResetPasswordExpiresAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 300000;
|
|
|
|
|
|
|
|
await UsersRepository.updateUserAsync(user);
|
2023-06-12 10:27:27 +00:00
|
|
|
|
|
|
|
msg = "Sending...";
|
2023-06-12 18:46:44 +00:00
|
|
|
|
|
|
|
Postman.sendMail(user.Email,
|
2023-06-08 21:34:59 +00:00
|
|
|
"Password Reset",
|
|
|
|
"Reset your Password using this link:\n" +
|
|
|
|
$"https://bulletboards.xyz/sys/click/resetpw/{user.UserID}/{hash}");
|
|
|
|
msg = "A reset email has been sent to the selected email, if that email is registered here. The link expires in 5 Minutes";
|
|
|
|
}
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-06-08 21:34:59 +00:00
|
|
|
}
|