- registration with local user accounts stub

This commit is contained in:
Dominik 2012-01-27 15:11:24 +01:00
parent f95fa32c2b
commit 20ba88890d
2 changed files with 44 additions and 0 deletions

View file

@ -87,6 +87,8 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
("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.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.local_username_label", value<std::string>()->default_value("Local username:"), "Label for local usernme field")
("database.type", value<std::string>()->default_value("none"), "Database type.")
("database.database", value<std::string>()->default_value(""), "Database used to store data")
("database.server", value<std::string>()->default_value("localhost"), "Database server.")

View file

@ -241,6 +241,20 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
boolean->setLabel((("Remove your registration")));
boolean->setValue(0);
form->addField(boolean);
} else {
if (CONFIG_BOOL(m_config,"registration.require_local_account")) {
std::string localUsernameField = CONFIG_STRING(m_config, "registration.local_username_label");
TextSingleFormField::ref local_username = TextSingleFormField::create();
local_username->setName("local_username");
local_username->setLabel((localUsernameField));
local_username->setRequired(true);
form->addField(local_username);
TextPrivateFormField::ref local_password = TextPrivateFormField::create();
local_password->setName("local_password");
local_password->setLabel((("Local Password")));
local_password->setRequired(true);
form->addField(local_password);
}
}
reg->setForm(form);
@ -273,6 +287,8 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
std::string encoding;
std::string language;
std::string local_username("");
std::string local_password("");
Form::ref form = payload->getForm();
if (form) {
@ -290,6 +306,13 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
else if (textSingle->getName() == "password") {
payload->setPassword(textSingle->getValue());
}
else if (textSingle->getName() == "local_username") {
local_username = textSingle->getValue();
}
// Pidgin sends it as textSingle, not sure why...
else if (textSingle->getName() == "local_password") {
local_password = textSingle->getValue();
}
continue;
}
@ -298,6 +321,9 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
if (textPrivate->getName() == "password") {
payload->setPassword(textPrivate->getValue());
}
else if (textPrivate->getName() == "local_password") {
local_password = textPrivate->getValue();
}
continue;
}
@ -327,6 +353,22 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
return true;
}
if (CONFIG_BOOL(m_config,"registration.require_local_account")) {
/* if (!local_username || !local_password) {
sendResponse(from, id, InBandRegistrationPayload::ref());
return true
} else */ if (local_username == "" || local_password == "") {
sendResponse(from, id, InBandRegistrationPayload::ref());
return true;
} else if (local_username != "heinz" || local_password != "heinz") {
// TODO: Check local password and username
sendError(from, id, ErrorPayload::NotAuthorized, ErrorPayload::Modify);
return true;
}
}
printf("here\n");
if (!payload->getUsername() || !payload->getPassword()) {
sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
return true;