summaryrefslogtreecommitdiffstats
path: root/src/modules/UserBackendMysql/UserBackendMysql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/UserBackendMysql/UserBackendMysql.cpp')
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp51
1 files changed, 48 insertions, 3 deletions
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<boost::mutex> 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<boost::mutex> 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<boost::mutex> 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();
+}
+
}
}
}