Changeset - bff117e4ef23
[Not reviewed]
0 5 0
Jan Kaluza - 10 years ago 2016-02-19 12:51:17
jkaluza@redhat.com
Slack: For IRC allow registering without providing account name/password
5 files changed with 40 insertions and 11 deletions:
0 comments (0 inline, 0 general)
libtransport/Config.cpp
Show inline comments
 
@@ -95,34 +95,36 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		("service.reuse_old_backends", value<bool>()->default_value(true), "True if Spectrum should use old backends which were full in the past.")
 
		("service.idle_reconnect_time", value<int>()->default_value(0), "Time in seconds after which idle users are reconnected to let their backend die.")
 
		("service.memory_collector_time", value<int>()->default_value(0), "Time in seconds after which backend with most memory is set to die.")
 
		("service.more_resources", value<bool>()->default_value(false), "Allow more resources to be connected in server mode at the same time.")
 
		("service.enable_privacy_lists", value<bool>()->default_value(true), "")
 
		("service.enable_xhtml", value<bool>()->default_value(true), "")
 
		("service.max_room_list_size", value<int>()->default_value(100), "")
 
		("service.login_delay", value<int>()->default_value(0), "")
 
		("service.jid_escaping", value<bool>()->default_value(true), "")
 
		("service.vip_only", value<bool>()->default_value(false), "")
 
		("service.vip_message", value<std::string>()->default_value(""), "")
 
		("service.reconnect_all_users", value<bool>()->default_value(false), "")
 
		("service.frontend", value<std::string>()->default_value("xmpp"), "")
 
		("service.web_directory", value<std::string>()->default_value(""), "Full path to directory used to save files to which the links are sent to users.")
 
		("service.web_url", value<std::string>()->default_value(""), "URL on which files in web_directory are accessible.")
 
		("vhosts.vhost", value<std::vector<std::string> >()->multitoken(), "")
 
		("identity.name", value<std::string>()->default_value("Spectrum 2 Transport"), "Name showed in service discovery.")
 
		("identity.category", value<std::string>()->default_value("gateway"), "Disco#info identity category. 'gateway' by default.")
 
		("identity.type", value<std::string>()->default_value(""), "Type of transport ('icq','msn','gg','irc', ...)")
 
		("registration.enable_public_registration", value<bool>()->default_value(true), "True if users should be able to register.")
 
		("registration.language", value<std::string>()->default_value("en"), "Default language for registration form")
 
		("registration.instructions", value<std::string>()->default_value("Enter your legacy network username and password."), "Instructions showed to user in registration form")
 
		("registration.username_label", value<std::string>()->default_value("Legacy network username:"), "Label for username field")
 
		("registration.username_label", value<std::string>()->default_value("3rd-party network username"), "Label for username field")
 
		("registration.password_label", value<std::string>()->default_value("3rd-party network password"), "Label for password field")
 
		("registration.username_mask", value<std::string>()->default_value(""), "Username mask")
 
		("registration.allowed_usernames", value<std::string>()->default_value(""), "Allowed usernames")
 
		("registration.auto_register", value<bool>()->default_value(false), "Register new user automatically when the presence arrives.")
 
		("registration.encoding", value<std::string>()->default_value("utf8"), "Default encoding in registration form")
 
		("registration.require_local_account", value<bool>()->default_value(false), "True if users have to have a local account to register to this transport from remote servers.")
 
		("registration.notify_jid", value<std::vector<std::string> >()->multitoken(), "Send message to this JID if user registers/unregisters")
 
		("registration.local_username_label", value<std::string>()->default_value("Local username:"), "Label for local usernme field")
 
		("registration.local_account_server", value<std::string>()->default_value("localhost"), "The server on which the local accounts will be checked for validity")
 
		("registration.local_account_server_timeout", value<int>()->default_value(10000), "Timeout when checking local user on local_account_server (msecs)")
 
		("gateway_responder.prompt", value<std::string>()->default_value("Contact ID"), "Value of <prompt> </promt> field")
 
		("gateway_responder.label", value<std::string>()->default_value("Enter legacy network contact ID."), "Label for add contact ID field")
 
		("database.type", value<std::string>()->default_value("none"), "Database type.")
spectrum/src/frontends/slack/SlackFrontend.cpp
Show inline comments
 
@@ -114,24 +114,29 @@ void SlackFrontend::connectToServer() {
 
	m_transport->handleConnected();
 
}
 

	
 
std::string SlackFrontend::setOAuth2Code(const std::string &code, const std::string &state) {
 
	return static_cast<SlackUserManager *>(m_userManager)->handleOAuth2Code(code, state);
 
}
 

	
 
std::string SlackFrontend::getOAuth2URL(const std::vector<std::string> &args) {
 
	return static_cast<SlackUserManager *>(m_userManager)->getOAuth2URL(args);
 
}
 

	
 
std::string SlackFrontend::getRegistrationFields() {
 
	return "Main Slack channel\n3rd-party network username\n3rd-party network password";
 
	std::string fields = "Main Slack channel";
 
	if (CONFIG_BOOL(m_config, "registration.needRegistration")) {
 
		fields += "\n" + CONFIG_STRING(m_config, "registration.username_label") + "\n";
 
		fields += CONFIG_STRING(m_config, "registration.password_label");
 
	}
 
	return fields;
 
}
 

	
 
bool SlackFrontend::handleAdminMessage(Swift::Message::ref message) {
 
	return static_cast<SlackUserManager *>(m_userManager)->handleAdminMessage(message);
 
}
 

	
 
void SlackFrontend::disconnectFromServer() {
 

	
 
}
 

	
 
}
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -247,24 +247,36 @@ void APIServer::serve_instances_register(Server *server, Server::session *sessio
 

	
 
	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");
 

	
 
	// For some networks like IRC, there is no registration.
 
	// We detect such networks according to registration_fields and use
 
	// "unknown" uin for them.
 
	if (uin.empty()) {
 
		std::string response = server->send_command(instance, "registration_fields");
 
		std::vector<std::string> fields;
 
		boost::split(fields, response, boost::is_any_of("\n"));
 
		if (fields.size() == 1) {
 
			uin = "unknown";
 
		}
 
	}
 

	
 
	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);
 
@@ -354,37 +366,36 @@ void APIServer::serve_instances_join_room_form(Server *server, Server::session *
 
	json.AddMember("frontend_room_label", "Slack channel", json.GetAllocator());
 
	send_json(conn, json);
 
}
 

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

	
 
	std::string response = server->send_command(instance, "registration_fields");
 
	std::vector<std::string> fields;
 
	boost::split(fields, response, boost::is_any_of("\n"));
 

	
 
	if (fields.size() < 3) {
 
		fields.clear();
 
	if (fields.empty()) {
 
		fields.push_back("Jabber ID");
 
		fields.push_back("3rd-party network username");
 
		fields.push_back("3rd-party network password");
 
	}
 

	
 
	Document json;
 
	json.SetObject();
 
	json.AddMember("error", 0, json.GetAllocator());
 
	json.AddMember("username_label", fields[0].c_str(), json.GetAllocator());
 
	json.AddMember("legacy_username_label", fields[1].c_str(), json.GetAllocator());
 
	json.AddMember("password_label", fields[2].c_str(), json.GetAllocator());
 
	json.AddMember("legacy_username_label", fields.size() >= 2 ? fields[1].c_str() : "", json.GetAllocator());
 
	json.AddMember("password_label", fields.size() >= 3 ? fields[2].c_str() : "", json.GetAllocator());
 
	send_json(conn, json);
 
}
 

	
 
void APIServer::serve_users(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	ALLOW_ONLY_ADMIN();
 

	
 
	Document json;
 
	json.SetObject();
 
	json.AddMember("error", 0, json.GetAllocator());
 

	
 
	std::vector<std::string> list;
 
	m_storage->getUsers(list);
spectrum_manager/src/html/instances/register.shtml
Show inline comments
 
<!--#include virtual="/header.shtml" -->
 

	
 
<h2>Register Spectrum 2 instance</h2>
 
<form action="/api/v1/instances/register" class="basic-grey" method="POST"> 
 
<h1>Register Spectrum 2 instance 
 
	<span id="description"></span> 
 
</h1> 
 
<label> 
 
	<span id="jid_desc"></span> 
 
	<input type="text" id="jid" name="jid" placeholder=""></textarea> 
 
</label> 
 
<label> 
 
<label id="uin_label"> 
 
	<span id="uin_desc"></span> 
 
	<input type="text" id="uin" name="uin" placeholder=""></textarea> 
 
</label> 
 
<label><span id="password_desc"></span> 
 
<label id="password_label"><span id="password_desc"></span> 
 
	<input type="password" id="password" name="password" placeholder=""></textarea> 
 
</label> 
 
<label> 
 
	<span>&nbsp;</span> 
 
	<input type="submit" class="button_command" value="Register" />
 
</label> 
 
<input type="hidden" name="instance" id="instance" value=""></input> 
 
</form><br/>
 

	
 
<script type="text/javascript">
 
$(function() {
 
	fill_instances_register_form();
spectrum_manager/src/html/js/app.js
Show inline comments
 
@@ -176,30 +176,41 @@ function fill_instances_register_form() {
 
		$.post($.cookie("base_location") + "api/v1/instances/register/" + $("#instance").val(), postdata, function(data) {
 
			if (data.oauth2_url) {
 
				window.location.replace(data.oauth2_url);
 
			}
 
			else {
 
				window.location.replace("index.shtml");
 
			}
 
		});
 
	})
 
	
 
	$.get($.cookie("base_location") + "api/v1/instances/register_form/" + query.id, function(data) {
 
		$("#jid_desc").html(data.username_label + ":");
 
		$("#uin_desc").html(data.legacy_username_label + ":");
 
		$("#password_desc").html(data.password_label + ":");
 

	
 
		$("#jid").attr("placeholder", data.username_label);
 

	
 
		if (data.legacy_username_label.length == 0) {
 
			$('#uin_label').hide();
 
		}
 
		else {
 
			$("#uin_desc").html(data.legacy_username_label + ":");
 
			$("#uin").attr("placeholder", data.legacy_username_label);
 
		}
 

	
 
		if (data.password_label.length == 0) {
 
			$('#password_label').hide();
 
		}
 
		else {
 
			$("#password_desc").html(data.password_label + ":");
 
			$("#password").attr("placeholder", data.password_label);
 
		}
 
	});
 
}
 

	
 
function fill_users_register_form() {
 
	$(".button").click(function(e) {
 
		e.preventDefault();
 

	
 
		var postdata ={
 
			"username": $("#username").val(),
 
			"password": $("#password").val()
 
		};
 

	
0 comments (0 inline, 0 general)