Ejemplo n.º 1
0
        public ActionResult UserLogin(UserLoginDto userLoginDto)
        {
            var target = _repo.GetUserByUsername(userLoginDto.username);

            if (target != null && _auth.ComparePasswords(userLoginDto.password, target.password))
            {
                return(Ok(new AuthenticationResultSuccessDto {
                    success = true,
                    token = _auth.CreateToken(target)
                }));
            }

            return(Unauthorized(new AuthenticationResultFailedDto()
            {
                errors = new [] { ErrorMessages.invalidCredentials }
            }));
        }