Exemplo n.º 1
0
        public IActionResult Login([FromForm] UserLoginDTO user)
        {
            if (!_reCaptcha.Validate(user.ReCaptchaToken))
            {
                return(Ok(new Status {
                    Success = false, Errors = new[] { "Invalid ReCaptcha." }
                }));
            }

            var userCtx = _context.Users.SingleOrDefault(x => x.UserName == user.UserName);

            if (userCtx == null)
            {
                return(Ok(new Status {
                    Success = false, Errors = new[] { "Invalid UserName or Password." }
                }));
            }

            if (!_userLogin.VerifyPassword(user.Password, userCtx.Salt, userCtx.Hash))
            {
                return(Ok(new Status {
                    Success = false, Errors = new[] { "Invalid UserName or Password." }
                }));
            }

            return(Ok(new Status {
                Success = true, Token = _userLogin.Authenticate(userCtx)
            }));
        }