@page "/sys/click/confirmmail/{userid}/{email}/{token}"
@using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Data.Repository
Confirm your Email
@msg
@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 = "This is not a valid id.";
return;
}
var user = await UsersRepository.getUserByIdAsync(int.Parse(userid));
if (user == null)
{
msg = "Could not find user.";
return;
}
if (user.Email != email)
{
msg = "The email does not match.";
return;
}
if (user.ConfirmEmailToken != token)
{
msg = "The token is not correct.";
return;
}
user.ConfirmEmailToken = "0";
user.ConfirmedEmail = true;
await UsersRepository.updateUserAsync(user);
msg = "The email has been confirmed.";
}
}