Changeset - 9391c487b518
[Not reviewed]
0 3 0
Jan Kaluza - 9 years ago 2016-02-19 09:16:08
jkaluza@redhat.com
Web interface: Allow registering with no password
3 files changed with 10 insertions and 3 deletions:
0 comments (0 inline, 0 general)
libtransport/AdminInterface.cpp
Show inline comments
 
@@ -247,53 +247,58 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
	}
 
	else if (msg == "crashed_backends") {
 
		std::string lst;
 
		const std::vector<std::string> &backends = m_server->getCrashedBackends();
 
		BOOST_FOREACH(const std::string &backend, backends) {
 
			lst += backend + "\n";
 
		}
 
		message->setBody(lst);
 
	}
 
	else if (msg == "crashed_backends_count") {
 
		message->setBody(boost::lexical_cast<std::string>(m_server->getCrashedBackends().size()));
 
	}
 
	else if (msg == "messages_from_xmpp") {
 
		int msgCount = m_userManager->getMessagesToBackend();
 
		message->setBody(boost::lexical_cast<std::string>(msgCount));
 
	}
 
	else if (msg == "messages_to_xmpp") {
 
		int msgCount = m_userManager->getMessagesToXMPP();
 
		message->setBody(boost::lexical_cast<std::string>(msgCount));
 
	}
 
	else if (msg.find("register ") == 0 && m_userRegistration) {
 
		std::string body = msg;
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 4) {
 
		if (args.size() == 4 || args.size() == 3) {
 
			UserInfo res;
 
			res.jid = args[1];
 
			res.uin = args[2];
 
			if (args.size() == 3) {
 
				res.password = args[3];
 
			}
 
			else {
 
				res.password = args[4];
 
			}
 
			res.language = "en";
 
			res.encoding = "utf-8";
 
			res.vip = 0;
 

	
 
			if (m_userRegistration->registerUser(res)) {
 
				message->setBody("User registered.");
 
			}
 
			else {
 
				message->setBody("Registration failed: User is already registered");
 
			}
 
		}
 
		else {
 
			message->setBody("Bad argument count. See 'help'.");
 
		}
 
	}
 
	else if (msg.find("unregister ") == 0 && m_userRegistration) {
 
		std::string body = msg;
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 2) {
 
			if (m_userRegistration->unregisterUser(args[1])) {
 
				message->setBody("User '" + args[1] + "' unregistered.");
 
			}
 
			else {
spectrum/src/frontends/slack/SlackUserRegistration.cpp
Show inline comments
 
@@ -126,51 +126,53 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
 
		}
 
		else {
 
			return "Received state code '" + state + "' not found in state codes list.";
 
		}
 

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

	
 
		if (token.empty()) {
 
			LOG4CXX_INFO(logger, "Using 'token' as 'bot_access_token'");
 
			token = access_token;
 
		}
 
	}
 

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

	
 
	std::string slackChannel;
 
	std::string uin;
 
	std::string password;
 
	if (data.size() == 4) {
 
	if (data.size() >= 3) {
 
		slackChannel = data[1];
 
		uin = data[2];
 
	}
 
	if (data.size() == 4) {
 
		password = data[3];
 
	}
 

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

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

	
 
	registerUser(user, true);
 

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

	
 
	if (!slackChannel.empty()) {
 
		m_storageBackend->getUserSetting(user.id, "slack_channel", type, slackChannel);
 
	}
 

	
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -235,49 +235,49 @@ void APIServer::serve_instances_unregister(Server *server, Server::session *sess
 
		else {
 
			send_ack(conn, true, "Unknown error.");
 
		}
 
	}
 
	else {
 
		send_ack(conn, true, "You are not registered to this Spectrum 2 instance.");
 
	}
 
}
 

	
 
void APIServer::serve_instances_register(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 

	
 
	UserInfo info;
 
	m_storage->getUser(session->user, info);
 

	
 
	std::string username = "";
 
	int type = (int) TYPE_STRING;
 
	m_storage->getUserSetting(info.id, instance, type, username);
 

	
 
	std::string jid = get_http_var(hm, "jid");
 
	std::string uin = get_http_var(hm, "uin");
 
	std::string password = get_http_var(hm, "password");
 

	
 
	if (jid.empty() || uin.empty() || password.empty()) {
 
	if (jid.empty() || uin.empty()) {
 
		send_ack(conn, true, "Insufficient data.");
 
	}
 
	else {
 
		// Check if the frontend wants to use OAuth2 (Slack for example).
 
		std::string response = server->send_command(instance, "get_oauth2_url " + jid + " " + uin + " " + password);
 
		if (!response.empty()) {
 
			Document json;
 
			json.SetObject();
 
			json.AddMember("error", false, json.GetAllocator());
 
			json.AddMember("oauth2_url", response.c_str(), json.GetAllocator());
 
			send_json(conn, json);
 
		}
 
		else {
 
			response = server->send_command(instance, "register " + jid + " " + uin + " " + password);
 
			if (!response.empty()) {
 
				std::string value = jid;
 
				int type = (int) TYPE_STRING;
 
				m_storage->updateUserSetting(info.id, instance, value);
 
			}
 
			else {
 
				send_ack(conn, true, response);
 
				return;
 
			}
 
		}
0 comments (0 inline, 0 general)