From ece09d41b776472419101092e66aac6df555b18f 2012-03-26 18:10:25 From: HanzZ Date: 2012-03-26 18:10:25 Subject: [PATCH] registration.auto_register option --- diff --git a/backends/libcommuni/singleircnetworkplugin.cpp b/backends/libcommuni/singleircnetworkplugin.cpp index f668e5438b7f498025e6cf63df360af037c086b5..af44ccfac5e31814267a3fb7c6343b1ff237d790 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 5962cc2548a788f499ce1ce6f91f4eeed7999951..816e6fba89d80da967efadc1b1a27c63ca7f9026 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 2a9666d483030cfa026790ee059a5069e5e71a56..671509f45614716c0bcde841534a3c16e56a4497 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");