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
 
@@ -259,29 +259,34 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
	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 {
spectrum/src/frontends/slack/SlackUserRegistration.cpp
Show inline comments
 
@@ -138,27 +138,29 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
 
			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;
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -247,25 +247,25 @@ 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");
 

	
 
	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);
 
		}
0 comments (0 inline, 0 general)