Example #1
0
        public static void SeedUsers(HeroicallyRecipesDbContext context)
        {
            if (context.Users.Count() > 1)
            {
                return;
            }

            string[] usernames = new string[] { "jhonDoe", "batman" };
            string[] passwords = new string[] { "jhonDoe123", "batman123" };
            string[] emails = new string[] { "[email protected]", "[email protected]" };

            PasswordHasher hasher = new PasswordHasher();
            var userManager = new UserManager<User>(new UserStore<User>(context));

            for (int i = 0; i < usernames.Length; i++)
            {
                var user = new User
                {
                    UserName = emails[i],
                    Email = emails[i],
                    NickName = emails[i],
                    PasswordHash = hasher.HashPassword(passwords[i]),
                    AvatarUrl = "/images/defaultAvatar1.png"
                };

                context.Users.Add(user);
                context.SaveChanges();
                userManager.UpdateSecurityStamp(user.Id);
            }
        }
Example #2
0
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
        {
            // N2 backward compatibility: generate security stamp when undefined yet
            if (string.IsNullOrEmpty(this.SecurityStamp))
            {
                manager.UpdateSecurityStamp(this.Id);
                this.SecurityStamp = manager.FindById(this.Id).SecurityStamp;
            }

            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            ClaimsIdentity userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            // See also: http://forums.asp.net/t/1973959.aspx?ASP+NET+MVC+5+OWIN+Missing+added+claims
            return userIdentity;
        }