bulletboards/ImageBoardServerApp/Pages/Accounts/ClickOn/ClickOnConfirmEmail.razor

61 lines
1.4 KiB
Text
Raw Normal View History

@page "/sys/click/confirmmail/{userid}/{email}/{token}"
@using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data.Repository
<h3>Confirm your Email</h3>
<span>@msg</span>
@code {
private string msg { get; set; } = "Loading...";
[Parameter]
[Required]
public string userid { get; set; }
[Parameter]
[Required]
public string email { get; set; }
[Parameter]
[Required]
public string token { get; set; }
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
if (!int.TryParse(userid, out _))
{
msg = "malformed userid.";
return;
}
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
if (user == null)
{
msg = "Could not find user.";
return;
}
if (user.Email != email)
{
msg = "This email is not specified to this account.";
return;
}
if (user.ConfirmEmailToken != token)
{
msg = "This token is not associated with the specified account.";
return;
}
user.ConfirmEmailToken = "-1";
user.ConfirmedEmail = true;
await UsersRepository.updateUserAsync(user);
msg = "The email has been confirmed.";
}
}