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

            dbContext.UserClaims.AddRange(
                new UserClaim(Guid.NewGuid(), "100", JwtClaimTypes.Subject, "100"),
                new UserClaim(Guid.NewGuid(), "100", JwtClaimTypes.Role, "Customer"),
                new UserClaim(Guid.NewGuid(), "100", JwtClaimTypes.Email, "*****@*****.**")
                );

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