Exemplo n.º 1
0
void Recaptcha::http_done(const boost::system::error_code& e,
                          const Http::Message& response) {
    if (e) {
        mistake(tr("wc.captcha.Internal_error"));
    } else if (boost::starts_with(response.body(), "true")) {
        solve();
    } else if (boost::contains(response.body(), "incorrect-captcha-sol")) {
        mistake(tr("wc.captcha.Wrong_response"));
    } else {
        mistake(tr("wc.captcha.Internal_error"));
    }
    updates_poster(WServer::instance(), wApp);
}
Exemplo n.º 2
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);
      }
    }
Exemplo 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);
    }
  }
Exemplo n.º 4
0
void Recaptcha::check_impl() {
    std::string challenge = value_text(challenge_field_).toUTF8();
    std::string response = value_text(response_field_).toUTF8();
    const std::string& remoteip = wApp->environment().clientAddress();
    Http::Message m;
    m.setHeader("Content-Type", "application/x-www-form-urlencoded");
    m.addBodyText("privatekey=" + private_key_ + "&");
    m.addBodyText("remoteip=" + remoteip + "&");
    m.addBodyText("challenge=" + urlencode(challenge) + "&");
    m.addBodyText("response=" + urlencode(response) + "&");
#ifdef WT_WITH_SSL
    std::string schema = "https";
#else
    std::string schema = "http";
#endif
    if (!http_->post(schema + "://www.google.com/recaptcha/api/verify", m)) {
        mistake(tr("wc.captcha.Internal_error"));
    }
}