public ActionResult Register(RegisterModel model, string returnUrl) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }); WebSecurity.Login(model.UserName, model.Password); //Send them an email UserMailer mailer = new UserMailer(); var mvcMailMessage = mailer.Welcome(model.UserName); var emailMessage = new SendEmailMessage() { Body = mvcMailMessage.Body, To = model.Email, Subject = "Welcome to YouConf" }; SendQueueMessage(emailMessage); if (!String.IsNullOrWhiteSpace(returnUrl)) { return RedirectToLocal(returnUrl); } return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public virtual ActionResult ForgotPassword(string email, bool captchaValid, string captchaErrorMessage) { if (!captchaValid) { ModelState.AddModelError("captcha", captchaErrorMessage); } if (ModelState.IsValid) { var user = YouConfDbContext.UserProfiles .FirstOrDefault(x => x.Email == email); if (user != null && user.UserId > 0 && OAuthWebSecurity.HasLocalAccount(user.UserId)) { string token = WebSecurity.GeneratePasswordResetToken(user.UserName); //Send them an email UserMailer mailer = new UserMailer(); var mvcMailMessage = mailer.PasswordReset(user.Email, user.UserName, token); var emailMessage = new SendEmailMessage() { Body = mvcMailMessage.Body, To = user.Email, Subject = "Password reset request" }; SendQueueMessage(emailMessage); return View("PasswordResetEmailSent"); } } return View(); }