Changeset - cd005935e254
[Not reviewed]
0 1 0
Jan Kaluza - 10 years ago 2016-02-19 17:16:34
jkaluza@redhat.com
Web interface: Allow joining rooms with white-spaces in the nickname
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -268,96 +268,97 @@ void APIServer::serve_instances_register(Server *server, Server::session *sessio
 
		}
 
	}
 

	
 
	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;
 
			}
 
		}
 
	}
 
}
 

	
 
void APIServer::serve_instances_join_room(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);
 

	
 
	if (username.empty()) {
 
		send_ack(conn, true, "You are not registered to this Spectrum 2 instance.");
 
		return;
 
	}
 

	
 
	std::string name = get_http_var(hm, "name");
 
	boost::replace_all(name, " ", "_");
 
	std::string legacy_room = get_http_var(hm, "legacy_room");
 
	std::string legacy_server = get_http_var(hm, "legacy_server");
 
	std::string frontend_room = get_http_var(hm, "frontend_room");
 

	
 
	std::string response = server->send_command(instance, "join_room " +
 
		username + " " + name + " " + legacy_room + " " + legacy_server + " " + frontend_room);
 

	
 
	if (response.find("Joined the room") == std::string::npos) {
 
		send_ack(conn, true, response);
 
	}
 
	else {
 
		send_ack(conn, false, response);
 
	}
 
}
 

	
 
void APIServer::serve_instances_leave_room(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);
 

	
 
	if (username.empty()) {
 
		send_ack(conn, true, "You are not registered to this Spectrum 2 instance.");
 
		return;
 
	}
 

	
 
	std::string frontend_room = get_http_var(hm, "frontend_room");
 
	std::string response = server->send_command(instance, "leave_room " + username + " " + frontend_room);
 

	
 
	if (response.find("Left the room") == std::string::npos) {
 
		send_ack(conn, true, response);
 
	}
 
	else {
 
		send_ack(conn, false, response);
 
	}
 
}
 

	
 
void APIServer::serve_instances_join_room_form(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	// So far we support just Slack here. For XMPP, it is up to user to initiate the join room request.
 
	Document json;
 
	json.SetObject();
 
	json.AddMember("error", 0, json.GetAllocator());
 
	json.AddMember("name_label", "Nickname in 3rd-party room", json.GetAllocator());
0 comments (0 inline, 0 general)