Esempio n. 1
0
        public async Task<IActionResult> ConfirmEmail(ResetPasswordViewModel model, string rememberMe = null, string returnUrl = null)
        {

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var user = await _userManager.FindByEmailAsync(model.Email);
            if (user == null)
            {
                // Don't reveal that the user does not exist
                return RedirectToAction(nameof(AccountController.ResetPasswordConfirmation), "Account");
            }
            var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

            if (result.Succeeded)
            {
                var signInResult = await _signInManager.PasswordSignInAsync(user, model.Password, model.RememberMe, lockoutOnFailure: false);
                if (signInResult.Succeeded)
                {
                    return RedirectToAction(nameof(HomeController.Index), "Home");
                }
                if (signInResult.RequiresTwoFactor)
                {
                    return RedirectToAction(nameof(SendCode), new { rememberMe, returnUrl });
                }
                if (signInResult.IsLockedOut)
                {
                    _logger.LogWarning(2, "User account locked out.");
                    return View("Lockout");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, T["Invalid login attempt."]);
                    if (signInResult.IsNotAllowed)
                        ModelState.AddModelError(string.Empty, T["Email or phonenumber not confirmed"]);
                    return View(model);
                }
            }
            AddErrors(result);
            return View();
        }
Esempio n. 2
0
        public async Task<IActionResult> ResetPassword(ResetPasswordViewModel model)
        {

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var user = await _userManager.FindByEmailAsync(model.Email) ?? await _userManager.FindByNameAsync(model.Email);
            if (user == null)
            {
                // Don't reveal that the user does not exist
                _logger.LogInformation("Could not find user with email {email}", model.Email);
                return RedirectToAction(nameof(AccountController.ResetPasswordConfirmation), "Account");
            }
            var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

            if (result.Succeeded)
            {
                return RedirectToAction(nameof(AccountController.ResetPasswordConfirmation), "Account");
            }
            AddErrors(result);
            return View();
        }
Esempio n. 3
0
        public async Task<IActionResult> ConfirmEmail(string userId, string confirmCode)
        {
            if (userId == null || confirmCode == null)
            {
                return View("Error");
            }
            var user = await _userManager.FindByIdAsync(userId);
            if (user == null)
            {
                return View("Error");
            }
            var result = await _userManager.ConfirmEmailAsync(user, confirmCode);
            if (!result.Succeeded)
            {
                AddErrors(result);

                return View("Error");
            }
            var model = new ResetPasswordViewModel()
            {
                Code = await _userManager.GeneratePasswordResetTokenAsync(user),
                Email = user.Email
            };
            return View(nameof(ConfirmEmail), model);
        }