Changeset - 20ba88890d2a
[Not reviewed]
0 2 0
Dominik - 13 years ago 2012-01-27 15:11:24
meyerd@mytum.de
- registration with local user accounts stub
2 files changed with 44 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/config.cpp
Show inline comments
 
@@ -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.")
src/userregistration.cpp
Show inline comments
 
@@ -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;
0 comments (0 inline, 0 general)