Exemplo n.º 1
0
        /// <summary>
        /// Seed the users by creating a OkbUser and Profile for each user.  Takes a list of provinces
        /// and randomizes the location of each user.  Uses the UserProfileBulkReader to generate random
        /// profiles.
        /// </summary>
        public void SeedUsers(int numOfUsers, IList<LocationPinyinModel> provinces, int commitCount = 100)
        {
            var db = new OkbDbContext();
            var profileGen = new ProfileGenerator(provinces);
            var userManager = new UserManager<OkbUser, string>(new UserStore<OkbUser>(db));

            db.Configuration.AutoDetectChangesEnabled = false;

            for (int i = 1; i < numOfUsers; i++)
            {
                var email = "test" + i + "@okboba.com";
                var user = new OkbUser
                {
                    UserName = email,
                    Email = email,
                    PasswordHash = userManager.PasswordHasher.HashPassword("password"),
                    SecurityStamp = Guid.NewGuid().ToString(),
                    JoinDate = DateTime.Now
                };

                var profile = profileGen.Next();

                user.Profile = profile;
                profile.UserId = user.Id;

                db.Users.Add(user);

                if (i % commitCount == 0)
                {
                    db.SaveChanges();
                    db.Dispose();
                    db = new OkbDbContext();
                    db.Configuration.AutoDetectChangesEnabled = false;
                }
            }

            db.SaveChanges();
        }
Exemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new OkbUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    JoinDate = DateTime.Now,
                    LastLoginDate = DateTime.Now
                };

                var profile = new Profile
                {
                    Gender = model.Gender,
                    LookingForGender = model.LookingForGender,
                    Birthdate = model.Birthdate,
                    Nickname = model.Nickname,
                    LocationId1 = model.LocationId1,
                    LocationId2 = model.LocationId2,
                    UserId = user.Id
                };

                user.Profile = profile;

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

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

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    //Update activity feed
                    var profileId = _profileRepo.GetProfileId(user.Id);
                    _feedRepo.JoinedActivity(profileId);

                    return RedirectToAction("Index", "Home");
                }

                //AddErrors(result);
            }

            // If we got this far, something failed, redisplay form 
            // Re-populate model with provinces           
            var prov = _locationRepo.GetProvinces();
            model.JsonProvinces = JsonConvert.SerializeObject(prov);
            return View(model);
        }