Changeset - 3f59eeef9537
[Not reviewed]
0 1 0
Sarang Bharadwaj - 13 years ago 2012-05-27 19:25:23
sarang.bh@gmail.com
Using storage backed to store user data. Removed the bug in the previous commit
1 file changed with 15 insertions and 20 deletions:
0 comments (0 inline, 0 general)
backends/twitter/main.cpp
Show inline comments
 
@@ -118,26 +118,24 @@ class TwitterPlugin : public NetworkPlugin {
 
			connectionState[user] = NEW;			
 
			sessions[user]->setTwitterUsername(username);
 
			sessions[user]->setTwitterPassword(passwd); 
 
			sessions[user]->getOAuth().setConsumerKey(consumerKey);
 
			sessions[user]->getOAuth().setConsumerSecret(consumerSecret);
 
			
 
			LOG4CXX_INFO(logger, "Querying database for user " << user)
 
			LOG4CXX_INFO(logger, "Querying database for usersettings of " << user)
 
			
 
			UserInfo info;
 
			storagebackend->getUser(user, info);
 

	
 
			UserInfo info;	
 
			if(storagebackend->getUser(user, info) == false/*registeredUsers.count(user) == 0*/) {			
 
				LOG4CXX_INFO(logger, "Creating database entry for user " << user)
 
				exit(0);
 
				info.jid = user;
 
				info.password = "";
 
				info.uin = username;
 
				info.language = "";
 
				info.encoding = "";
 
				info.vip = false;
 
				info.id = 0;
 
				storagebackend->setUser(info);
 
			std::string key="", secret="";
 
			int type;
 
			storagebackend->getUserSetting((long)info.id, OAUTH_KEY, type, key);
 
			storagebackend->getUserSetting((long)info.id, OAUTH_SECRET, type, secret);
 

	
 
			if(key == "" || secret == ""/*registeredUsers.count(user) == 0*/) {			
 
				LOG4CXX_INFO(logger, "Intiating oauthflow for user " << user)
 

	
 
				std::string authUrl;
 
				if (sessions[user]->oAuthRequestToken( authUrl ) == false ) {
 
					LOG4CXX_ERROR(logger, "Error creating twitter authorization url!");
 
					handleLogoutRequest(user, username);
 
					return;
 
@@ -146,16 +144,13 @@ class TwitterPlugin : public NetworkPlugin {
 
				handleMessage(user, "twitter-account", std::string("Please reply with the PIN provided by twitter. Prefix the pin with 'pin:'. Ex. 'pin: 1234'"));
 
				connectionState[user] = WAITING_FOR_PIN;	
 
			} else {
 
				//std::vector<std::string> keysecret;
 
				//db->fetch(user, keysecret);
 
				LOG4CXX_INFO(logger, user << " is already registerd. Using the stored oauth key and secret")
 
				std::string key, secret;
 
				int type;
 
				storagebackend->getUserSetting((long)info.id, OAUTH_KEY, type, key);
 
				storagebackend->getUserSetting((long)info.id, OAUTH_SECRET, type, secret);
 
				LOG4CXX_INFO(logger, key << " " << secret)
 

	
 
				sessions[user]->getOAuth().setOAuthTokenKey( key );
 
				sessions[user]->getOAuth().setOAuthTokenSecret( secret );
 
				connectionState[user] = CONNECTED;
 
			}
 
		}
 
@@ -304,19 +299,19 @@ int main (int argc, char* argv[]) {
 
		return 1;
 
	}
 

	
 
	Logging::initBackendLogging(&config);
 
	
 
	std::string error;
 
	StorageBackend *storageBackend = StorageBackend::createBackend(&config, error);
 
	if (storageBackend == NULL) {
 
	storagebackend = StorageBackend::createBackend(&config, error);
 
	if (storagebackend == NULL) {
 
		LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error)
 
		return -2;
 
	}
 

	
 
	else if (!storageBackend->connect()) {
 
	else if (!storagebackend->connect()) {
 
		LOG4CXX_ERROR(logger, "Can't connect to database!")
 
		return -1;
 
	}
 

	
 
	Swift::SimpleEventLoop eventLoop;
 
	loop_ = &eventLoop;
0 comments (0 inline, 0 general)