예제 #1
0
 // GET: /Account/ForgotPassword
 public ActionResult ForgotPassword()
 {
     ForgotPasswordModel model = new ForgotPasswordModel();
         return View(model);
 }
예제 #2
0
        public ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            //Check valid email, process password reset
                if (ModelState.IsValid)
                {

                    AccountService.ProcessForgotPassword(model);
                    return RedirectToAction("EmailSent", "Content", new { });
                }

                return View(model);
        }
예제 #3
0
        public void ProcessForgotPassword(ForgotPasswordModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {
                //Get user info
                var user = Session.Query<AccountUserDocument>().Where(x => x.Email == model.Email).SingleOrDefault();

                //Create return email object
                BCryptService crypto = new BCryptService();
                var identifier = crypto.GenerateToken();
                var resetDocument = new ReturnEmailDocument
                {
                    UserId = user.Id,
                    Email = user.Email,
                    Identifier = identifier,
                    Hash = crypto.Hash(identifier),
                    Timestamp = DateTime.Now

                };

                //Creste reset Url
                resetDocument.ResetUrl = ConfigurationManager.AppSettings["BaseUrl"] + "Account/ResetPassword?prc=" + System.Uri.EscapeDataString(resetDocument.Hash);

                //Persist reset object
                Session.Store(resetDocument);
                Session.SaveChanges();

                //Send the email
                if (user != null)
                {
                    EmailModel emailProperties = new EmailModel();
                    emailProperties.ToAddress = user.Email;
                    emailProperties.FirstName = user.FirstName;
                    emailProperties.ReturnUrl = resetDocument.ResetUrl;
                    new MailController().ForgotPasswordEmail(emailProperties).Deliver();

                }
                else
                {
                    throw new UserNotFoundException("User not found by specified email address");
                }

            }
        }