public ActionResult Index()
        {
            AssertAdminUserExists();

            var email = string.Format("admin@{0}", ConfigurationManager.AppSettings["Domain"]);
            var vm = new RegisterViewModel
            {
                Email = email,
                ConfirmEmail = email
            };

            return View(vm);
        }
        public void CanLogOnAfterRegisteringAndVerifyingAccount()
        {
            // register
            var model = new RegisterViewModel
                {
                    FirstName = "F",
                    LastName = "L",
                    Email = "*****@*****.**",
                    ConfirmEmail = "*****@*****.**",
                    Password = "******"
                };

            var controller1 = new AccountController(Mock.Of<IAuthenticationService>()) { DocumentSession = Session };
            using (DomainEvent.Disable()) controller1.Register(model);

            // normally done by infrastructure (special action filter)
            Session.SaveChanges();

            // verify
            var registeredUser = Session.FindUserByEmail("*****@*****.**");
            Assert.NotNull(registeredUser);
            var key = registeredUser.ActivationKey;

            var controller2 = new AccountController(Mock.Of<IAuthenticationService>()) { DocumentSession = Session };
            controller2.Verify(Guid.Parse(key));

            // logon
            var loggedOn = false;
            var service = Mock.Of<IAuthenticationService>();
            Mock.Get(service)
                .Setup(s => s.SetAuthCookie(It.Is<string>(e => e == "*****@*****.**"), It.IsAny<bool>()))
                .Callback(() => loggedOn = true);

            var controller3 = new AccountController(service)
                {
                    DocumentSession = Session,
                    Url = CreateUrlHelper()
                };
            controller3.LogOn(
                new LogOnViewModel
                    {
                        Email = "*****@*****.**",
                        Password = "******"
                    },
                string.Empty);

            Assert.True(loggedOn);
        }
        public ActionResult CreateAdmin(RegisterViewModel adminUser)
        {
            AssertAdminUserExists();

            if (!ModelState.IsValid)
                return View("Index");

            var user = new User(
                adminUser.FirstName,
                adminUser.LastName,
                adminUser.Email,
                adminUser.Password)
                {
                    Id = "Admin"
                };
            user.Activate();
            DocumentSession.Store(user);

            return RedirectToAction("Success");
        }
        public ActionResult Register(RegisterViewModel model)
        {
            // an existing user cannot be registered again
            if (DocumentSession.FindUserByEmail(model.Email) != null)
                ModelState.AddModelError("Email", "Adressen finns redan.");

            // redisplay form if any errors at this point
            if (!ModelState.IsValid)
                return View(model);

            var newUser = new User(model.FirstName, model.LastName, model.Email, model.Password);
            newUser.Initialize();
            DocumentSession.Store(newUser);

            return RedirectToAction("RegisterSuccess");
        }