From ece09d41b776472419101092e66aac6df555b18f Mon Sep 17 00:00:00 2001 From: HanzZ Date: Mon, 26 Mar 2012 18:10:25 +0200 Subject: [PATCH] registration.auto_register option --- .../libcommuni/singleircnetworkplugin.cpp | 10 ++++--- src/config.cpp | 1 + src/usermanager.cpp | 28 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/backends/libcommuni/singleircnetworkplugin.cpp b/backends/libcommuni/singleircnetworkplugin.cpp index f668e543..af44ccfa 100644 --- a/backends/libcommuni/singleircnetworkplugin.cpp +++ b/backends/libcommuni/singleircnetworkplugin.cpp @@ -50,10 +50,12 @@ void SingleIRCNetworkPlugin::handleLoginRequest(const std::string &user, const s session->setHost(QString::fromStdString(m_server)); session->setPort(6667); - std::string identify = m_identify; - boost::replace_all(identify, "$password", password); - boost::replace_all(identify, "$name", legacyName); - session->setIdentify(identify); + if (!password.empty()) { + std::string identify = m_identify; + boost::replace_all(identify, "$password", password); + boost::replace_all(identify, "$name", legacyName); + session->setIdentify(identify); + } session->open(); diff --git a/src/config.cpp b/src/config.cpp index 5962cc25..816e6fba 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -93,6 +93,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description ("registration.instructions", value()->default_value("Enter your legacy network username and password."), "Instructions showed to user in registration form") ("registration.username_label", value()->default_value("Legacy network username:"), "Label for username field") ("registration.username_mask", value()->default_value(""), "Username mask") + ("registration.auto_register", value()->default_value(false), "Register new user automatically when the presence arrives.") ("registration.encoding", value()->default_value("utf8"), "Default encoding in registration form") ("registration.require_local_account", value()->default_value(false), "True if users have to have a local account to register to this transport from remote servers.") ("registration.local_username_label", value()->default_value("Local username:"), "Label for local usernme field") diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 2a9666d4..671509f4 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -214,6 +214,34 @@ void UserManager::handlePresence(Swift::Presence::ref presence) { res.password = m_userRegistry->getUserPassword(userkey); } + // We allow auto_register feature in gateway-mode. This allows IRC user to register + // the transport just by joining the room. + if (!m_component->inServerMode()) { + if (!registered && CONFIG_BOOL(m_component->getConfig(), "registration.auto_register")) { + res.password = ""; + res.jid = userkey; + + bool isMUC = presence->getPayload() != NULL || *presence->getTo().getNode().c_str() == '#'; + if (isMUC) { + res.uin = presence->getTo().getResource(); + } + else { + res.uin = presence->getFrom().toString(); + } + LOG4CXX_INFO(logger, "Auto-registering user " << userkey << " with uin=" << res.uin); + + if (m_storageBackend) { + // store user and getUser again to get user ID. + m_storageBackend->setUser(res); + registered = m_storageBackend->getUser(userkey, res); + } + else { + registered = false; + } + } + } + + // Unregistered users are not able to login if (!registered) { LOG4CXX_WARN(logger, "Unregistered user " << userkey << " tried to login");