public async Task <IActionResult> Confirm(ConfirmModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError("NotFound", "A user with the given email address was not found");
                    return(View(model));
                }

                if (!await _userManager.IsEmailConfirmedAsync(user))
                {
                    var result = await _userManager.ConfirmSignUpAsync(user, model.Code, true);

                    // var result = await _userManager.ConfirmEmailAsync(user, model.Code);
                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                }
            }
            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    ModelState.AddModelError("Not Found", "A user with the given email address was not found");
                    return(View(model));
                }

                await user.ForgotPasswordAsync();
            }

            return(View(model));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(Input.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(RedirectToPage("./ResetPassword"));
                }

                // Cognito will send notification to user with reset token the user can use to reset their password.
                await user.ForgotPasswordAsync();

                return(RedirectToPage("./ResetPassword"));
            }

            return(Page());
        }