コード例 #1
0
        private static void SeedUsers(DataContext context)
        {
            var store       = new CustomUserStore(context);
            var userManager = new AccountUserManager(store);

            var user1 = new UserAccount {
                UserName = "******", Email = "*****@*****.**"
            };
            var user2 = new UserAccount {
                UserName = "******", Email = "*****@*****.**"
            };

            var profile1 = new Profile {
                Name         = "Jar Jar Binks",
                Age          = 30, Location = "Naboo",
                SearchingFor = "Female",
                Gender       = "Male",
                UserPhoto    = null,
                Description  = "Something about me..",
                Visible      = Visible.Yes,
                UserAccount  = user1
            };

            var profile2 = new Profile
            {
                Name         = "Leia Organa",
                Age          = 45,
                Location     = "Alderaan",
                SearchingFor = "Male",
                Gender       = "Female",
                UserPhoto    = null,
                Description  = "Something about me..",
                Visible      = Visible.Yes,
                UserAccount  = user2
            };

            userManager.CreateAsync(user1, "User1!").Wait();
            userManager.CreateAsync(user2, "User2!").Wait();

            context.Profiles.Add(profile1);
            context.Profiles.Add(profile2);
        }
コード例 #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new UserAccount {
                    UserName = model.Email, Email = model.Email
                };
                var result = await accountUserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await applicationSignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", result.Errors.FirstOrDefault());
                }
            }

            return(View(model));
        }