Changeset - 495d881c5a91
[Not reviewed]
0 2 0
HanzZ - 13 years ago 2012-09-13 10:38:06
hanzz.k@gmail.com
registration.needPassword works
2 files changed with 33 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/tests/userregistration.cpp
Show inline comments
 
@@ -30,6 +30,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
	CPPUNIT_TEST(unregisterEmptyPayload);
 
	CPPUNIT_TEST(changePassword);
 
	CPPUNIT_TEST(registerUserEmpty);
 
	CPPUNIT_TEST(registerUserNoNeedPassword);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
@@ -213,6 +214,30 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unsubscribed, dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getType());
 
		}
 

	
 
		void registerUserNoNeedPassword() {
 
			cfg->updateBackendConfig("[registration]\nneedPassword=0\n");
 
			Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
 
			reg->setUsername("legacyname");
 
			boost::shared_ptr<Swift::IQ> iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", boost::shared_ptr<Swift::Payload>(reg));
 
			iq->setFrom("user@localhost");
 
			injectIQ(iq);
 
			loop->processEvents();
 

	
 
			CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribe, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
 

	
 
			UserInfo user;
 
			CPPUNIT_ASSERT_EQUAL(true, storage->getUser("user@localhost", user));
 

	
 
			CPPUNIT_ASSERT_EQUAL(std::string("legacyname"), user.uin);
 
			CPPUNIT_ASSERT_EQUAL(std::string(""), user.password);
 
		}
 

	
 
};
 

	
 
CPPUNIT_TEST_SUITE_REGISTRATION (UserRegistrationTest);
src/userregistration.cpp
Show inline comments
 
@@ -189,8 +189,9 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
	reg->setInstructions(instructions);
 
	reg->setRegistered(registered);
 
	reg->setUsername(res.uin);
 
	if (CONFIG_STRING(m_config, "service.protocol") != "twitter" && CONFIG_STRING(m_config, "service.protocol") != "bonjour")
 
	if (CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true)) {
 
		reg->setPassword("");
 
	}
 

	
 

	
 
	// form
 
@@ -210,7 +211,7 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
	username->setRequired(true);
 
	form->addField(username);
 

	
 
	if (CONFIG_STRING(m_config, "service.protocol") != "twitter" && CONFIG_STRING(m_config, "service.protocol") != "bonjour") {
 
	if (CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true)) {
 
		TextPrivateFormField::ref password = TextPrivateFormField::create();
 
		password->setName("password");
 
		password->setLabel((("Password")));
 
@@ -397,11 +398,15 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
		}
 
	}
 

	
 
	if (!payload->getUsername() || !payload->getPassword()) {
 
	if (!payload->getUsername() || (!payload->getPassword() && CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true))) {
 
		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	if (!payload->getPassword()) {
 
		payload->setPassword("");
 
	}
 

	
 
	// Register or change password
 
	if (payload->getUsername()->empty()) {
 
		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
0 comments (0 inline, 0 general)