Ejemplo n.º 1
0
    // this method is called when REST response is received for request to get user information:
    void handleMe(boost::system::error_code err, const Http::Message& response)
    {
#ifndef WT_TARGET_JAVA
      WApplication::instance()->resumeRendering();
#endif

      if (!err && response.status() == 200) {
#ifndef WT_TARGET_JAVA
        Json::ParseError e;
        Json::Object me;
        bool ok = Json::parse(response.body(), me, e);
#else
        Json::Object me;
        try {
	         me = (Json::Object)Json::Parser().parse(response.body());
        } 
        catch (Json::ParseError pe) {
        }
        bool ok = me.isNull();
#endif

        if (!ok) {
	        LOG_ERROR("could not parse JSON: '" << response.body() << "'");
	        setError(ERROR_MSG("badjson"));
	        authenticated().emit(Identity::Invalid);
        } 
        else {
	        std::string id = me.get("id");
          std::string email = me.get("emailAddress");
          
          if (getUserProfileAsJson)
          {
            // In the Identity's name field more complete user info is passed in JSON format as returned from LinkedIn, see details at:
            // https://developer.linkedin.com/docs/fields/basic-profile
            authenticated().emit(Identity(service().name(), id, response.body(), email, true));
          }
          else
          {
            std::string name = me.get("firstName");
            name += std::string(" ");
            name += std::string(me.get("lastName"));
            authenticated().emit(Identity(service().name(), id, name, email, true));
          }
        }
      } 
      else {
        if (!err) {
	        LOG_ERROR("user info request returned: " << response.status());
	        LOG_ERROR("with: " << response.body());
        } 
        else {
          LOG_ERROR("handleMe(): " << err.message());
        }
        setError(ERROR_MSG("badresponse"));
        authenticated().emit(Identity::Invalid);
      }
    }
Ejemplo n.º 2
0
WeatherForecast::WeatherForecast(const Json::Object &json)
    : _city(json.get("city"))
{
    _count = json.get("cnt").toNumber().orIfNull(0);
    _cod = json.get("cod").toString().orIfNull("");
    Json::Array weathers = json.get("list");
    for(auto w: weathers) {
        _weathers.push_back({w});
    }
}
Ejemplo n.º 3
0
  void handleMe(boost::system::error_code err, const Http::Message& response)
  {
#ifndef WT_TARGET_JAVA
    WApplication::instance()->resumeRendering();
#endif

    if (!err && response.status() == 200) {
#ifndef WT_TARGET_JAVA
      Json::ParseError e;
      Json::Object me;
      bool ok = Json::parse(response.body(), me, e);
#else
      Json::Object me;
      try {
	me = (Json::Object)Json::Parser().parse(response.body());
      } catch (Json::ParseError pe) {
      }
      bool ok = me.isNull();
#endif

      if (!ok) {
	LOG_ERROR("could not parse Json: '" << response.body() << "'");
	setError(ERROR_MSG("badjson"));
	authenticated().emit(Identity::Invalid);
      } else {
	std::string id = me.get("id");
	WT_USTRING userName = me.get("name");
	std::string email = me.get("email").orIfNull("");
        bool emailVerified = !me.get("email").isNull();

	authenticated().emit(Identity(service().name(), id, userName,
				      email, emailVerified));
      }
    } else {
      if (!err) {
	LOG_ERROR("user info request returned: " << response.status());
	LOG_ERROR("with: " << response.body());
      } else
	LOG_ERROR("handleMe(): " << err.message());

      setError(ERROR_MSG("badresponse"));

      authenticated().emit(Identity::Invalid);
    }
  }