Beispiel #1
0
        public static void SeedUsers(IUserDataContext userDataContext, IPhotosDataContext photosDataContext)
        {
            if (!userDataContext.GetAllUsersByLastActive().Result.Any())
            {
                System.Console.WriteLine("Seeding users...");
                var userData = System.IO.File.ReadAllText("Data/UserSeedData.json");
                var users    = JsonConvert.DeserializeObject <List <User> >(userData);
                foreach (var user in users)
                {
                    byte[] passwordHash, passwordSalt;
                    CreatePasswordHash("password", out passwordHash, out passwordSalt);

                    user.PasswordHash = passwordHash;
                    user.PasswordSalt = passwordSalt;
                    user.Username     = user.Username.ToLower();
                    userDataContext.Add(user);

                    foreach (var photo in user.PhotosFromSeed)
                    {
                        photo.UserId = userDataContext.GetByUsername(user.Username).Result.Id;
                        photosDataContext.Add(photo);
                    }
                }
                System.Console.WriteLine("User Seed complete.");
            }
        }
Beispiel #2
0
        public async Task <User> Login(string username, string password)
        {
            var user = await _userDataContext.GetByUsername(username);

            //var user = await _context.Users.Include(p => p.Photos).FirstOrDefaultAsync(x => x.Username == username);

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

            if (!VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                return(null);
            }

            return(user);
        }