public static string PasswordReset(string userName) { try { var user = Membership.GetUser(userName); var newPassword = user.ResetPassword(); var message = new MailService.MessageModel { UserName = userName, MessageSubject = "Password reset notification", MessageBody = "Your password has been reset to: " + newPassword }; MailService.SendConfirmationEmail(message); return ("Success"); } catch { return ("Error"); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { ViewBag.PasswordLength = MembershipService.MinPasswordLength; if (ValidateRegistration(model.UserName, model.Email, model.Password, model.ConfirmPassword)) { MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); if (createStatus == MembershipCreateStatus.Success) { // TODO: SendConfirmationEmail() might fail, try-catch here! string confirmationGuid = Membership.GetUser(model.UserName).ProviderUserKey.ToString(); string confirmUrl = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/account/confirm?id=" + confirmationGuid; var message = new MailService.MessageModel { UserName = model.UserName, MessageSubject = "Registration confirmation from WebPresentations.com", MessageBody = "Please follow the link below in order to activate your account:\n" + confirmUrl }; MailService.SendConfirmationEmail(message); return RedirectToAction("Confirmation", "Account"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } } return View(model); }