Пример #1
0
        public async Task <IActionResult> Create(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            user.password = Cryptic.GetHash(user.password);
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            user.password = "";
            return(CreatedAtAction(nameof(GetById), new { id = user.Id }, user));
        }
Пример #2
0
        public async Task <ActionResult <User> > Validate(User user)
        {
            //Ideally this should be in different controller

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var founduser = await _context.Users.Where(o => o.Name == user.Name).FirstOrDefaultAsync();

            if (founduser != null && (Cryptic.GetHash(user.password) == founduser.password))
            {
                user.password = "";
                return(user);
            }

            return(NotFound());
        }
Пример #3
0
        public static void Initialize(UserContext context)
        {
            if (!context.Users.Any())
            {
                context.Users.AddRange(
                    new User
                {
                    Name     = "Madison",
                    password = Cryptic.GetHash("Secret")
                },
                    new User
                {
                    Name     = "Randy",
                    password = Cryptic.GetHash("Secret2")
                }
                    );;;;

                context.SaveChanges();
            }
        }