public UserAuthenticateResponseModel AuthenticateUser(UserAuthenticateRequestModel model) { // validation var results = _userValidator.Validate(model).ToArray(); if (results.Length > 0) { throw new ValidationApiException(results); } // get the user from the repository / database var entity = _repo.GetUsers().SingleOrDefault(user => user.Email == model.Email && user.Password == model.Password); // throw unathorized exception if user doesn't exist if (entity == null) { throw new UnauthorizedApiException("Username or password is incorrect"); } if (entity.Locked) { throw new UnauthorizedApiException("Account is locked"); } // authentication successful so generate jwt token var token = GenerateJwtToken(entity.Id); //return the UserAuthenticateResponseModel to the controller return(_userMapper.AuthenticateMapper(entity, token)); }