public ActionResult RequestRecovery(RegisterModel register) { var profile = _repositiory.UserProfiles.FirstOrDefault(x => x.EmailAddress.ToLower() == register.EmailAddress.ToLower()); if (profile != null) { TempData["StatusMessage"] = "Instructions on how to reset your password have been sent to your email address."; var baseUrl = Request.Url != null ? Request.Url.GetLeftPart(UriPartial.Authority) : string.Empty; _mailService.SendEmail(profile.EmailAddress, profile.UserName, "Password Recovery", EmailType.PasswordRecovery, new PasswordRecovery { UserName = profile.UserName, RecoveryLink = baseUrl + "/account/reset?token=" + WebSecurity.GeneratePasswordResetToken(profile.UserName) }); } else TempData["StatusMessage"] = "There is not an account on record with that email address."; return RedirectToAction("Recovery"); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { EmailAddress = model.EmailAddress }); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }