public EmailResult VerificationEmail(EmailModel emailModel)
 {
     To.Add(emailModel.ToAddress);
     From = ConfigurationManager.AppSettings["AdminEmail"].ToString();
     Subject = "Please confirm your email";
     return Email("VerificationEmail", emailModel);
 }
 public EmailResult ForgotPasswordEmail(EmailModel emailModel)
 {
     To.Add(emailModel.ToAddress);
     From = ConfigurationManager.AppSettings["AdminEmail"].ToString();
     Subject = "Reset your password";
     return Email("ForgotPasswordEmail", emailModel);
 }
        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");
                }

            }
        }
        public AccountUserDocument CreateUser(RegisterModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {

                //Persist the new user
                Guid userId = Guid.NewGuid();

                Session.Store(new AccountUserDocument
                {
                    Name = model.Email,
                    Id = String.Format("FacebookTest/Users/{0}", userId),
                    AllowedDatabases = new[] { "*" },

                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    FacebookId = 0,
                    Expires = DateTime.Now.AddMonths(1),
                    AccessToken = string.Empty

                }.SetPassword(model.Password));
                Session.SaveChanges();

                //Retrieve user from the document session
                var user = Session.Load<AccountUserDocument>(String.Format("FacebookTest/Users/{0}", userId));

                //Send Validation Email
                //Create return email object
                BCryptService crypto = new BCryptService();
                var identifier = crypto.GenerateToken();
                var returnEmailDocument = new ReturnEmailDocument
                {
                    UserId = user.Id,
                    Email = user.Email,
                    Identifier = identifier,
                    Hash = crypto.Hash(identifier)

                };

                //Creste reset Url
                returnEmailDocument.ResetUrl = ConfigurationManager.AppSettings["BaseUrl"] + "Account/Verify?vac=" + System.Uri.EscapeDataString(returnEmailDocument.Hash);

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

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

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

                return user;
            }
        }