bulletboards/ImageBoardServerApp/Pages/Accounts/ResetPassword.razor

56 lines
1.6 KiB
Text
Raw Permalink Normal View History

@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">
<RadzenTextBox @bind-Value="@Email"/>
</RadzenFormField>
<br/>
<br/>
<RadzenButton Click=@resetPassword Text="Send reset email" ButtonStyle="ButtonStyle.Secondary"/>
<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()
{
msg = "Checking...";
var user = await UsersRepository.getUserByEmailRawAsync(Email);
if (user == null)
{
msg = "This user is not registered.";
return;
}
Console.WriteLine("Resetting a password...");
msg = "Generating";
var hash = TheManager.getmd5Hash();
user.ResetPasswordToken = hash;
user.ResetPasswordExpiresAt = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 300000;
await UsersRepository.updateUserAsync(user);
msg = "Sending...";
Postman.sendMail(user.Email,
"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";
}
}