summaryrefslogtreecommitdiffstats
path: root/src/Client/UserCommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/UserCommands.cpp')
-rw-r--r--src/Client/UserCommands.cpp78
1 files changed, 78 insertions, 0 deletions
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;
+ }
+}
+
}
}