Exemplo n.º 1
0
        public ActionResult Index(SetupViewModel model)
        {
            if (ModelState.IsValid) {
                // Attempt to register the user
                MembershipCreateStatus createStatus = _membershipService.CreateUser(model.SetupModel.UserName, model.SetupModel.Password, model.SetupModel.Email);

                if (createStatus == MembershipCreateStatus.Success) {

                    _formsService.SignIn(model.SetupModel.UserName, false /* createPersistentCookie */);
                    // Create the site configuration
                    IConfiguration configuration = new Configuration.Configuration();
                    configuration.SiteName = model.Configuration.SiteName;
                    _session.Store(configuration);
                    IStructureInfo structureInfo = new StructureInfo();
                    _session.Store(structureInfo);
                    _session.SaveChanges();

                    return RedirectToAction("index", "UI", new { area = "ui" });
                }

                ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 2
0
        public async Task<ActionResult> Index(SetupViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }
            using (var session = _store.OpenSession()) {

                using (var userManager = Startup.UserManagerFactory.Invoke(session)) {

                    var user = new ApplicationUser
                    {
                        UserName = model.SetupModel.UserName,
                        Email = model.SetupModel.Email
                    };

                    session.Store(user);

                    var result = await userManager.CreateAsync(user, model.SetupModel.Password);

                    if (result.Succeeded) {
                        var identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
                        identity.AddClaim(new Claim(ClaimTypes.Email, user.Email));
                        GetAuthenticationManager().SignIn(identity);
                        Configuration configuration = new Configuration
                        {
                            SiteName = model.Configuration.SiteName
                        };
                        session.Store(configuration);
                        session.SaveChanges();
                        return RedirectToAction("Index", "UI", new { area = "UI" });
                    }

                    foreach (var error in result.Errors) {
                        ModelState.AddModelError("", error);
                    }

                    return View();
                }
            }
        }