From c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 7 Jul 2009 18:51:35 +0200 Subject: Added add_user command to client & UserBackendMysql --- src/Common/Backends/NetworkUserBackend.cpp | 28 +++++++++++++++++++++++----- src/Common/Backends/NetworkUserBackend.h | 15 ++++++++++++++- src/Common/UserManager.cpp | 22 ++++++++++------------ 3 files changed, 47 insertions(+), 18 deletions(-) (limited to 'src/Common') diff --git a/src/Common/Backends/NetworkUserBackend.cpp b/src/Common/Backends/NetworkUserBackend.cpp index 27f65f5..a1cf415 100644 --- a/src/Common/Backends/NetworkUserBackend.cpp +++ b/src/Common/Backends/NetworkUserBackend.cpp @@ -27,7 +27,7 @@ namespace Common { namespace Backends { void NetworkUserBackend::SimpleUserRequest::sendRequest() { - Common::XmlPacket packet; + XmlPacket packet; packet.setType(type); if(!timestamp.is_not_a_date_time()) @@ -37,7 +37,7 @@ void NetworkUserBackend::SimpleUserRequest::sendRequest() { } void NetworkUserBackend::IdUserRequest::sendRequest() { - Common::XmlPacket packet; + XmlPacket packet; packet.setType(type); packet.set(idType, id); @@ -48,7 +48,7 @@ void NetworkUserBackend::IdUserRequest::sendRequest() { } void NetworkUserBackend::NameUserRequest::sendRequest() { - Common::XmlPacket packet; + XmlPacket packet; packet.setType(type); packet.set("name", name); @@ -58,6 +58,18 @@ void NetworkUserBackend::NameUserRequest::sendRequest() { sendPacket(packet); } +void NetworkUserBackend::UserAddRequest::sendRequest() { + XmlPacket packet; + packet.setType("AddUser"); + + packet.set("uid", userInfo.getUid()); + packet.set("gid", userInfo.getGid()); + packet.set("username", userInfo.getUsername()); + packet.set("fullName", userInfo.getFullName()); + + sendPacket(packet); +} + boost::shared_ptr > NetworkUserBackend::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { boost::shared_ptr request(new SimpleUserRequest(application, "ListUsers", timestamp)); application->getRequestManager()->sendRequest(connection, request); @@ -327,9 +339,15 @@ boost::shared_ptr > NetworkUse }*/ -/*void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) { +void NetworkUserBackend::addUser(const UserInfo &userInfo) throw(Core::Exception) { + boost::shared_ptr request(new UserAddRequest(application, userInfo)); + application->getRequestManager()->sendRequest(connection, request); + request->wait(); -}*/ + std::pair, Core::Exception> result = request->getResult(); + if(!result.first || result.second) + throw result.second; +} } } diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h index 8faa8e3..9518790 100644 --- a/src/Common/Backends/NetworkUserBackend.h +++ b/src/Common/Backends/NetworkUserBackend.h @@ -71,6 +71,18 @@ class NetworkUserBackend : public UserBackend { : Request(application), type(type0), name(name0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {} }; + class UserAddRequest : public Request { + private: + UserInfo userInfo; + + protected: + virtual void sendRequest(); + + public: + UserAddRequest(Application *application, const UserInfo &userInfo0) + : Request(application), userInfo(userInfo0) {} + }; + Application *application; Connection *connection; @@ -88,7 +100,8 @@ class NetworkUserBackend : public UserBackend { virtual boost::shared_ptr > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); //virtual void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); - //virtual void addUser(const UserInfo &userInfo) throw(Core::Exception); + + virtual void addUser(const UserInfo &userInfo) throw(Core::Exception); public: NetworkUserBackend(Application *application0, Connection *connection0) : application(application0), connection(connection0) {} diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index 4031140..0ccf314 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -208,39 +208,37 @@ boost::shared_ptr > UserManage } void UserManager::setPassword(unsigned long uid, const std::string &password) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { backend->second->setPassword(uid, password); + return; } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; + catch(Core::Exception e) { + if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + throw e; } } - throw e; + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) { - Core::Exception e(Core::Exception::NOT_IMPLEMENTED); - boost::lock_guard lock(mutex); for(BackendMap::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { backend->second->addUser(userInfo); + return; } - catch(Core::Exception e2) { - if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - e = e2; + catch(Core::Exception e) { + if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) + throw e; } } - throw e; + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } } -- cgit v1.2.3