diff options
Diffstat (limited to 'src/Client/UserCommands.cpp')
-rw-r--r-- | src/Client/UserCommands.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index 96e9cc6..d58eaca 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -342,5 +342,79 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve } } +void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) { + if(args.size() < 3) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("add_user_to_group"); + return; + } + if(args.size() > 3) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("add_user_to_group"); + 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("add_user_to_group"); + return; + } + + unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); + if(args[2].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("add_user_to_group"); + return; + } + + try { + commandParser->application->getUserManager()->addUserToGroup(uid, gid); + + std::cout << "Added." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + +void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) { + if(args.size() < 3) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("delete_user_from_group"); + return; + } + if(args.size() > 3) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("delete_user_from_group"); + 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_from_group"); + return; + } + + unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); + if(args[2].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("delete_user_from_group"); + return; + } + + try { + commandParser->application->getUserManager()->deleteUserFromGroup(uid, gid); + + std::cout << "Removed." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + } } |