Пример #1
0
    public async Task <IActionResult> OnPostAsync()
    {
        var user = await _userManager.GetUserAsync(User);

        if (user == null)
        {
            return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
        }

        RequirePassword = await _userManager.HasPasswordAsync(user);

        if (RequirePassword)
        {
            if (!await _userManager.CheckPasswordAsync(user, Input.Password))
            {
                ModelState.AddModelError(string.Empty, "Incorrect password.");
                return(Page());
            }
        }

        await _userManager.DeleteUserAccount(user);

        await _signInManager.SignOutAsync();

        _logger.LogInformation("User with ID '{UserId}' deleted themselves.", user.Id);

        return(Redirect("~/"));
    }
Пример #2
0
        public async Task <IActionResult> DeleteAccount()
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(BadRequest());
            }

            await _userManager.DeleteUserAccount(user);

            return(Ok());
        }