public async Task <ActionResult> ForgotPassword(LoginForgotPasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var user = await UserMicroService.GetUserByNameAsync(model.Email); if (user == null) { throw new ServiceException("Invalid user ID or password."); } var userId = user.UserId; var isConfirmed = await UserMicroService.GetEmailConfirmedAsync(userId); if (isConfirmed) { await SendEmailResetAsync(userId); } return(RedirectToAction("ForgotPasswordConfirmation", "Login")); } catch (ServiceException ex) { AddModelErrors(ex); return(View()); } }
public async Task <ActionResult> Index(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View()); } try { var user = await UserMicroService.GetUserByNameAsync(model.Email); if (user == null) { throw new ServiceException("Invalid user ID or password."); } var userId = user.UserId; var confirmed = await UserMicroService.GetEmailConfirmedAsync(userId); if (!confirmed) { await SendConfirmationEmailAsync(userId); AddModelError("Your email address has not been confirmed. A confirmation email has been sent."); return(View()); } var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.IsPersistent, lockoutOnFailure : true); if (result.IsLockedOut) { AddModelError("This account has been locked out. Please reset your password to recover."); return(View()); } else if (result.RequiresTwoFactor) { // Used by two-factor authentication. return(View()); } else if (!result.Succeeded) { AddModelError("Invalid user ID or password."); return(View()); } UserLocale.RemoveFrom(HttpContext); return(RedirectToLocal(returnUrl)); } catch (ServiceException ex) { AddModelErrors(ex); return(View()); } }