summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-10 02:08:03 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-10 02:08:03 +0200
commitf892ec46086eee9c4bfb954469016829fb201532 (patch)
treec6abb16ea1b52953a37da995dc988c823685a46a /src/Client
parent5bf8b6ce656ffe0740ec116057577044e3925887 (diff)
downloadmad-f892ec46086eee9c4bfb954469016829fb201532.tar
mad-f892ec46086eee9c4bfb954469016829fb201532.zip
updateUser und deleteUser zum UserBackendMysql, NetworkUserBackend und Client hinzugefügt
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp4
-rw-r--r--src/Client/UserCommands.cpp78
-rw-r--r--src/Client/UserCommands.h2
3 files changed, 83 insertions, 1 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index efa48b9..6e8a7d3 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -51,7 +51,9 @@ const CommandParser::Command CommandParser::commands[] = {
{{"list_groups", "groups", 0}, "list_groups", "Show the user group database", "Show the user group database.", &UserCommands::listGroupsCommand},
{{"group_info", "group", 0}, "group_info gid|name", "Search for a group id", "Search for a group.", &UserCommands::groupInfoCommand},
{{"list_group_users", "group_users", 0}, "list_group_users gid", "List group's users", "List the users that are members of the group.", &UserCommands::listGroupUsersCommand},
- {{"add_user", 0}, "add_user uid gid username full_name", "Add a new user", "Adds a new user with the given info to the account database.", &UserCommands::addUserCommand},
+ {{"add_user", 0}, "add_user uid gid username full_name", "Add a new user", "Add a new user with the given info to the account database.", &UserCommands::addUserCommand},
+ {{"update_user", 0}, "update_user uid new_uid gid username full_name", "Update a user", "Update user data in the account database.", &UserCommands::updateUserCommand},
+ {{"delete_user", 0}, "delete_user uid", "Delete user", "Delete a user from the account database.", &UserCommands::deleteUserCommand},
{{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Close the connection and quit the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
};
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index 6bc2c11..96e9cc6 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -264,5 +264,83 @@ void UserCommands::addUserCommand(CommandParser *commandParser, const std::vecto
}
}
+void UserCommands::updateUserCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 6) {
+ std::cerr << args[0] << ": Too few arguments." << std::endl;
+ commandParser->printUsage("update_user");
+ return;
+ }
+ if(args.size() > 6) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("update_user");
+ return;
+ }
+
+ char *endptr;
+ unsigned long origUid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[1].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse the old user id." << std::endl;
+ commandParser->printUsage("update_user");
+ return;
+ }
+
+ unsigned long uid = std::strtoul(args[2].c_str(), &endptr, 10);
+ if(args[2].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse the new user id." << std::endl;
+ commandParser->printUsage("update_user");
+ return;
+ }
+
+ unsigned long gid = std::strtoul(args[3].c_str(), &endptr, 10);
+ if(args[3].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse group id." << std::endl;
+ commandParser->printUsage("update_user");
+ return;
+ }
+
+ try {
+ Common::UserInfo user(uid, args[4]);
+ user.setGid(gid);
+ user.setFullName(args[5]);
+
+ commandParser->application->getUserManager()->updateUser(origUid, user);
+
+ std::cout << "User updated." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
+void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 2) {
+ std::cerr << args[0] << ": No user id given." << std::endl;
+ commandParser->printUsage("delete_user");
+ return;
+ }
+ if(args.size() > 2) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("delete_user");
+ return;
+ }
+
+ char *endptr;
+ unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[1].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse user id." << std::endl;
+ commandParser->printUsage("delete_user");
+ return;
+ }
+
+ try {
+ commandParser->application->getUserManager()->deleteUser(uid);
+
+ std::cout << "User deleted." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
}
}
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index 0dc008d..2feb6a5 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -42,6 +42,8 @@ class UserCommands {
static void listGroupUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void addUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void updateUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void deleteUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
};
}