示例#1
0
        protected override void Dispose(bool disposing)
        {
            if (RavenSession != null)
            {
                RavenSession.Dispose();
            }

            base.Dispose(disposing);
        }
示例#2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View());
            }

            // Attempt to register the user
            RavenSession.Advanced.UseOptimisticConcurrency = true; // make sure we are not overwriting an existing user
            model.SendOutKey = Guid.NewGuid().ToString();
            RavenSession.Store(new User
            {
                Id         = "users/" + model.Email.ToLower(),
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                Email      = model.Email,
                DateJoined = DateTimeOffset.Now,
                Enabled    = false,
            }.SetPassword(model.Password));

            try
            {
                RavenSession.SaveChanges();
                RavenSession.Advanced.UseOptimisticConcurrency = false;

                //TaskExecutor.ExcuteLater(new SendEmailTask
                //{
                //    ReplyTo = "*****@*****.**",
                //    Subject = "You have a user in HibernatingRhinos.com!",
                //    SendTo = new[] { model.Email, "*****@*****.**" },
                //    ViewName = "RegistrationSuccessful",
                //    Model = model,
                //});

                return(RedirectToAction("RegistrationSuccessful"));
            }
            catch (ConcurrencyException)
            {
                ModelState.AddModelError("", "A user name for that e-mail address already exists. Please enter a different e-mail address.");
                RavenSession.Dispose();
                RavenSession = null;
            }

            //ModelState.AddModelError("", "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.");

            // If we got this far, something failed, redisplay form
            return(View(model));
        }