Esempio n. 1
0
        public static bool ValidatePassword(this IdentityDbContext 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);
        }
Esempio n. 2
0
        public static void SeedInMemory(this IdentityDbContext 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.SaveChanges();

            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.SaveChanges();

            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.SaveChanges();

            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();

            dbContext.Users.Add(new User("5000", "*****@*****.**", "password1".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "5000", JwtClaimTypes.Subject, "5000"),
                new UserClaim(Guid.NewGuid(), "5000", JwtClaimTypes.PreferredUserName, "warehousemanager1"),
                new UserClaim(Guid.NewGuid(), "5000", JwtClaimTypes.Role, "WarehouseManager"),
                new UserClaim(Guid.NewGuid(), "5000", JwtClaimTypes.Email, "*****@*****.**")
                );

            dbContext.SaveChanges();

            dbContext.Users.Add(new User("6000", "*****@*****.**", "password1".ToSha256(), true));

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "6000", JwtClaimTypes.Subject, "6000"),
                new UserClaim(Guid.NewGuid(), "6000", JwtClaimTypes.PreferredUserName, "warehouseoperator1"),
                new UserClaim(Guid.NewGuid(), "6000", JwtClaimTypes.Role, "WarehouseOperator"),
                new UserClaim(Guid.NewGuid(), "6000", JwtClaimTypes.Email, "*****@*****.**")
                );

            dbContext.SaveChanges();
        }
Esempio n. 3
0
 public static User GetUserByID(this IdentityDbContext dbContext, string id)
 => dbContext.Users.FirstOrDefault(item => item.UserID == id);
Esempio n. 4
0
 public static IEnumerable <UserClaim> GetUserClaimsByUserID(this IdentityDbContext dbContext, string userID)
 => dbContext.UserClaims.Where(item => item.UserID == userID);
Esempio n. 5
0
 public static User GetUserByUserName(this IdentityDbContext dbContext, string userName)
 => dbContext.Users.FirstOrDefault(item => item.Email == userName);