Changeset - 37ee8ce9804d
[Not reviewed]
0 1 0
Jan Kaluza - 10 years ago 2016-01-24 12:07:48
jkaluza@redhat.com
Remove wrong std::string token definition
1 file changed with 0 insertions and 1 deletions:
0 comments (0 inline, 0 general)
spectrum/src/frontends/slack/SlackUserRegistration.cpp
Show inline comments
 
@@ -79,97 +79,96 @@ std::string SlackUserRegistration::createOAuth2URL(const std::vector<std::string
 

	
 
std::string SlackUserRegistration::getTeamDomain(const std::string &token) {
 
	std::string url = "https://slack.com/api/team.info?token=" + Util::urlencode(token);
 

	
 
	rapidjson::Document resp;
 
	HTTPRequest req(HTTPRequest::Get, url);
 
	if (!req.execute(resp)) {
 
		LOG4CXX_ERROR(logger, url);
 
		LOG4CXX_ERROR(logger, req.getError());
 
		return "";
 
	}
 

	
 
	rapidjson::Value &team = resp["team"];
 
	if (!team.IsObject()) {
 
		LOG4CXX_ERROR(logger, "No 'team' object in the reply.");
 
		LOG4CXX_ERROR(logger, url);
 
		LOG4CXX_ERROR(logger, req.getRawData());
 
		return "";
 
	}
 

	
 
	rapidjson::Value &domain = team["domain"];
 
	if (!domain.IsString()) {
 
		LOG4CXX_ERROR(logger, "No 'domain' string in the reply.");
 
		LOG4CXX_ERROR(logger, url);
 
		LOG4CXX_ERROR(logger, req.getRawData());
 
		return "";
 
	}
 

	
 
	return domain.GetString();
 
}
 

	
 
std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, const std::string &state) {
 
	OAuth2 *oauth2 = NULL;
 
	std::string token;
 
	std::vector<std::string> data;
 

	
 
	if (state == "use_bot_token") {
 
		token = code;
 
	}
 
	else {
 
		if (m_auths.find(state) != m_auths.end()) {
 
			oauth2 = m_auths[state];
 
			data = m_authsData[state];
 
		}
 
		else {
 
			return "Received state code '" + state + "' not found in state codes list.";
 
		}
 

	
 
		std::string token;
 
		std::string error = oauth2->requestToken(code, token);
 
		if (!error.empty())  {
 
			return error;
 
		}
 
	}
 

	
 
	std::string domain = getTeamDomain(token);
 
	if (domain.empty()) {
 
		return "The token you have provided is invalid";
 
	}
 

	
 
	UserInfo user;
 
	user.uin = "";
 
	user.password = "";
 
	user.id = 0;
 
	m_storageBackend->getUser(domain, user);
 

	
 
	user.jid = domain;
 
	user.language = "en";
 
	user.encoding = "";
 
	user.vip = 0;
 

	
 
	registerUser(user, true);
 

	
 
	m_storageBackend->getUser(user.jid, user);
 

	
 
	std::string value = token;
 
	int type = (int) TYPE_STRING;
 
	m_storageBackend->getUserSetting(user.id, "bot_token", type, value);
 

	
 
	LOG4CXX_INFO(logger, "Registered Slack user " << user.jid);
 

	
 
	if (oauth2) {
 
		m_auths.erase(state);
 
		delete oauth2;
 

	
 
		m_authsData.erase(state);
 
	}
 

	
 
	m_component->getFrontend()->reconnectUser(user.jid);
 

	
 
	return "";
 
}
 

	
 
bool SlackUserRegistration::doUserRegistration(const UserInfo &row) {
 
	return true;
 
}
 

	
0 comments (0 inline, 0 general)