Пример #1
0
        public static void SeedInMemory(this AuthDbContext dbContext)
        {
            dbContext.Users.Add(new User("1000", "*****@*****.**", "magneto".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.Subject, "1000"),
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.PreferredUserName, "eriklehnsherr"),
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.Role, "Administrator"),
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.Email, "*****@*****.**"),
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.GivenName, "Erik"),
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.MiddleName, "M"),
                new UserClaim(Guid.NewGuid(), "1000", JwtClaimTypes.FamilyName, "Lehnsherr")
                );

            dbContext.Users.Add(new User("2000", "*****@*****.**", "professorx".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.Subject, "2000"),
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.PreferredUserName, "charlesxavier"),
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.Role, "Administrator"),
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.Email, "*****@*****.**"),
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.GivenName, "Charles"),
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.MiddleName, "F"),
                new UserClaim(Guid.NewGuid(), "2000", JwtClaimTypes.FamilyName, "Xavier")
                );

            dbContext.Users.Add(new User("3000", "*****@*****.**", "wolverine".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.Subject, "3000"),
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.PreferredUserName, "jameslogan"),
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.Role, "Customer"),
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.Email, "*****@*****.**"),
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.GivenName, "James"),
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.MiddleName, ""),
                new UserClaim(Guid.NewGuid(), "3000", JwtClaimTypes.FamilyName, "Logan")
                );

            dbContext.Users.Add(new User("4000", "*****@*****.**", "storm".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.Subject, "4000"),
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.PreferredUserName, "ororo_munroe"),
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.Role, "Customer"),
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.Email, "*****@*****.**"),
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.GivenName, "Ororo"),
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.MiddleName, ""),
                new UserClaim(Guid.NewGuid(), "4000", JwtClaimTypes.FamilyName, "Munroe")
                );

            dbContext.SaveChanges();
        }
Пример #2
0
        public static bool ValidatePassword(this AuthDbContext dbContext, string userName, string password)
        {
            var user = dbContext.Users.FirstOrDefault(item => item.Email == userName);

            if (user == null)
            {
                return(false);
            }

            if (user.Password == password.ToSha256())
            {
                return(true);
            }

            return(false);
        }
Пример #3
0
        public static void SeedInMemory(this AuthDbContext dbContext)
        {
            dbContext.Users.Add(new User("10000", "*****@*****.**", "wolverine".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.Subject, "10000"),
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.PreferredUserName, "jameslogan"),
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.Email, "*****@*****.**"),
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.Role, "Customer"),
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.GivenName, "James"),
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.MiddleName, ""),
                new UserClaim(Guid.NewGuid(), "10000", JwtClaimTypes.FamilyName, "Logan")
                );

            dbContext.SaveChanges();
        }
Пример #4
0
 public static IEnumerable <UserClaim> GetUserClaimsByUserID(this AuthDbContext dbContext, string userID)
 => dbContext.UserClaims.Where(item => item.UserID == userID);
Пример #5
0
 public static User GetUserByID(this AuthDbContext dbContext, string id)
 => dbContext.Users.FirstOrDefault(item => item.UserID == id);
Пример #6
0
 public static User GetUserByUserName(this AuthDbContext dbContext, string userName)
 => dbContext.Users.FirstOrDefault(item => item.Email == userName);