From f892ec46086eee9c4bfb954469016829fb201532 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 10 Jul 2009 02:08:03 +0200 Subject: =?UTF-8?q?updateUser=20und=20deleteUser=20zum=20UserBackendMysql,?= =?UTF-8?q?=20NetworkUserBackend=20und=20Client=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/UserBackendMysql/UserBackendMysql.cpp | 51 +++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'src/modules/UserBackendMysql/UserBackendMysql.cpp') diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp index 015c5a1..f169593 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.cpp +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -116,6 +116,14 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha if(entry[3].empty()) queryAddUser = entry[2][0]; } + else if(entry[2].getKey().matches("UpdateUser")) { + if(entry[3].empty()) + queryUpdateUser = entry[2][0]; + } + else if(entry[2].getKey().matches("DeleteUser")) { + if(entry[3].empty()) + queryDeleteUser = entry[2][0]; + } else if(!entry[2].empty()) return false; } @@ -463,9 +471,6 @@ void UserBackendMysql::addUser(const Common::UserInfo &userInfo) throw(Core::Exc boost::lock_guard lock(mutex); - if(!mysql || mysql_ping(mysql)) - throw Core::Exception(Core::Exception::NOT_AVAILABLE); - ArgumentMap args; args.insert(std::make_pair("UID", userInfo.getUid())); args.insert(std::make_pair("GID", userInfo.getGid())); @@ -484,6 +489,46 @@ void UserBackendMysql::addUser(const Common::UserInfo &userInfo) throw(Core::Exc lastUpdate = boost::posix_time::microsec_clock::universal_time(); } +void UserBackendMysql::updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::lock_guard lock(mutex); + + ArgumentMap args; + args.insert(std::make_pair("ORIG_UID", uid)); + args.insert(std::make_pair("UID", userInfo.getUid())); + args.insert(std::make_pair("GID", userInfo.getGid())); + args.insert(std::make_pair("USER", userInfo.getUsername())); + args.insert(std::make_pair("FULL_NAME", userInfo.getFullName())); + + Result result = query(queryUpdateUser, args); + + if(result.getErrno()) { + if(result.getErrno() == ER_DUP_ENTRY) + throw Core::Exception(Core::Exception::DUPLICATE_ENTRY); + else + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + } + + lastUpdate = boost::posix_time::microsec_clock::universal_time(); +} + +void UserBackendMysql::deleteUser(unsigned long uid) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::lock_guard lock(mutex); + + ArgumentMap args; + args.insert(std::make_pair("UID", uid)); + + Result result = query(queryDeleteUser, args); + + if(result.getErrno()) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + lastUpdate = boost::posix_time::microsec_clock::universal_time(); +} + } } } -- cgit v1.2.3