bulletboards/ImageBoardServerApp/Pages/Accounts/ResetPassword.razor
limited_dev 993c3c1a63 feat: added informatic output to the ResetPassword page
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
2023-06-12 12:27:27 +02:00

55 lines
No EOL
1.6 KiB
Text

@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";
}
}