Support for [registration] allowed_usernames

This commit is contained in:
Jan Kaluza 2012-08-01 13:50:38 +02:00
parent 132059ca7d
commit f081fe9187
2 changed files with 11 additions and 9 deletions

View file

@ -101,6 +101,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
("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_mask", value<std::string>()->default_value(""), "Username mask")
("registration.allowed_usernanames", 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.")

View file

@ -29,6 +29,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/regex.hpp>
using namespace Swift;
@ -441,15 +442,15 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
// return true;
// }
//TODO: Part of spectrum1 registration stuff, this should be potentially rewritten for S2 too
// #if GLIB_CHECK_VERSION(2,14,0)
// if (!CONFIG_STRING(m_config, "registration.reg_allowed_usernames").empty() &&
// !g_regex_match_simple(CONFIG_STRING(m_config, "registration.reg_allowed_usernames"), newUsername.c_str(),(GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_EXTENDED), (GRegexMatchFlags) 0)) {
// Log("UserRegistration", "This is not valid username: "<< newUsername);
// sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
// return true;
// }
// #endif
if (!CONFIG_STRING(m_config, "registration.allowed_usernames").empty()) {
boost::regex expression(CONFIG_STRING(m_config, "registration.allowed_usernames"));
if (!regex_match(newUsername, expression)) {
LOG4CXX_INFO(logger, "This is not valid username: " << newUsername);
sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
return true;
}
}
if (!registered) {
res.jid = barejid;
res.uin = newUsername;