[HttpPost] [ActionName("PasswordRecover")] [ValidateAntiForgeryToken] [AllowAnonymous] public ActionResult PasswordRecover_Post(LostPassword model) { if (ModelState.IsValid) { MembershipUser User; RegisterLogic register = new RegisterLogic(); UpdateModel(model); if (register.IsExist(model) == true) { var foundUserName = register.getName(model); if (foundUserName != null) { User = Membership.GetUser(foundUserName); } else { User = null; } if (User != null) { var token = WebSecurity.GeneratePasswordResetToken(User.UserName); string resetLink = "<a href='" + Url.Action("ResetPassword", "Pages", new { rt = token }, "http") + "'>Reset Password Link</a>"; // Email stuff string subject = "Reset your password for 1 KEY HPC"; string body = "Password recovery link: " + resetLink; string from = "donotreply@gmail.com"; //message.Subject = subject; //message.Body = body; MailMessage message = new MailMessage(from, model.Email,subject,body); SmtpClient client = new SmtpClient(); // Attempt to send the email try { client.Send(message); } catch (Exception e) { ModelState.AddModelError("", "Issue sending email: " + e.Message); } } else // Email not found { ModelState.AddModelError("", "No user found by that email."); } } else { ModelState.AddModelError("", "Email address does not exist."); } } return View(model); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)