public async Task<ActionResult> ResendConfirmationEmail(ResendConfirmationEmailViewModel model) { ActionResult rtnResult; if (ModelState.IsValid) { var user = await UserManager.FindByEmailAsync(model.Email); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id); rtnResult = View(); } else { rtnResult = View(); } } else { ViewBag.errorMessage = "Incorrect email."; rtnResult = View("Error"); } } else { rtnResult = View("Error"); } // If we got this far, something failed, redisplay form return rtnResult; }
public async Task <ActionResult> ResendConfirmationEmail(ResendConfirmationEmailViewModel model) { if (ModelState.IsValid) { var user = _userService.GetByEmailWithMembership(model.Email); if (user != null) { if (_userService.IsPasswordMatchForUser(user.UserID, model.Password)) { String confirmationLink = Url.Action("ConfirmAccount", "Account", new { email = user.Email, confirmationToken = user.Membership.AccountConfirmationToken }, Request.Url.Scheme); String subject = "Account Registration"; String body = "Thank you for signing up. In order to complete the registration process, please enter this address in " + "your browser's address bar." + confirmationLink; await _userService.SendEmailAsync(user.UserID, subject, body); ModelState.Clear(); ViewBag.SuccessMessage = "An email has been sent to you."; return(View()); } } ModelState.AddModelError("", "Invalid email or password."); } return(View(model)); }
public ActionResult ResendConfirmationEmail(String email) { var model = new ResendConfirmationEmailViewModel(); model.Email = email; return(View(model)); }
public ActionResult ConfirmationSent(ResendConfirmationEmailViewModel model) { if (model.Email == null) { return(RedirectToAction("ResendConfirmation", "Account")); } return(View(model)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } var user = UserManager.FindByEmail(model.Email); if (user != null) { if (UserManager.IsEmailConfirmed(user.Id)) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } } else { var emailModel = new ResendConfirmationEmailViewModel(); emailModel.Email = model.Email; return(View("EmailNotConfirmed", emailModel)); } } else { ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public async Task <ActionResult> ResendConfirmationEmail(ResendConfirmationEmailViewModel model) { if (!ModelState.IsValid) { return(View()); } var user = UserManager.FindByEmail(model.Email); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(View(model)); }
public ActionResult ResendConfirmation(ResendConfirmationEmailViewModel model) { if (ModelState.IsValid) { string userId = UserService.GetUserIdByEmail(model.Email); if (userId == null) { ModelState.AddModelError("Error", "There is no user with such email"); } else { string confirmationEmailLink = GetConfirmationLink(userId, model.Email); string userName = UserService.GetUserNameByEmail(model.Email); UserServiceResult result = UserService.SendConfirmationEmail(userName, model.Email, confirmationEmailLink); if (result == UserServiceResult.success) { return(RedirectToAction("ConfirmationSent", "Account", new ResendConfirmationEmailViewModel { Email = model.Email })); } if (result == UserServiceResult.emailNotSent) { ModelState.AddModelError("Error", "Email not sent"); } if (result == UserServiceResult.emailAlreadyConfirmed) { ModelState.AddModelError("Error", "Email already confirmed"); } } } ModelState.AddModelError("Error", "Something went wrong"); return(View(model)); }
public async Task <ActionResult> ResendConfirmationEmail([Bind(Include = "Email")] ResendConfirmationEmailViewModel model) { if (ModelState.IsValid) { ApplicationUser user = await UserManager.FindByEmailAsync(model.Email); if (user == null) { ViewBag.errorMessage = "Email not found. Check again your email if it is correct or register now " + Url.Action("Register", "Account"); return(View("Error")); } string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking: " + callbackUrl); ViewBag.Email = model.Email; return(View("VerifyAccount")); } return(View("Error")); }
public IActionResult ResendConfirmationEmail(ResendConfirmationEmailViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = getUserByEmail.Invoke(model.Email, model.DomainName); if (user == null) { Alert.Danger("We don't have this account in database"); return(View(model)); } if (user.EmailConfirmedOn != null) { Alert.Info("Email already confirmed"); return(RedirectToAction("Login")); } var token = addUserTokenToUser.Invoke(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Auth", new { token }, Request.Scheme); var emailInfo = new EmailBodyHelper().GetRegisterEmailBodyModel(callbackUrl); var stringView = RenderViewToString("EmailTemplate", emailInfo); var message = emailService.CreateMessage(model.Email, "Confirm your account", stringView); var mappedMessage = AutoMapper.Mapper.Map <EmailMessageModel>(message); addNewEmailMessage.Invoke(mappedMessage); Alert.Success("Check your inbox"); return(RedirectToAction("Login")); }