Example #1
0
    public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken)
    {
        var user = await _userManager.GetUserAsync(User);

        RequirePassword = await _userManager.HasPasswordAsync(user);

        if (RequirePassword)
        {
            // If the password is incorrect.
            if (!await _userManager.CheckPasswordAsync(user, Input.Password))
            {
                ModelState.AddModelError(string.Empty, _localizer["Error"]);
                return(Page());
            }
        }

        await _repository.DeleteCertificatesByUserId(user.Id, cancellationToken);

        await _userManager.DeleteAsync(user);

        _logger.LogInformation($"User {user.Id} has been deleted");

        await _signInManager.SignOutAsync();

        return(Redirect("~/"));
    }