From 758f3cf98f95fc906c2517c0d4537ce81cf7386d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 7 Aug 2009 00:12:52 +0200 Subject: UserBackendMysql, client: Added group administration --- src/Client/UserCommands.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) (limited to 'src/Client/UserCommands.cpp') diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index 43131c7..b93de94 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -320,6 +320,103 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve } } +void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vector &args) { + if(args.size() < 3) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("add_group"); + return; + } + if(args.size() > 3) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("add_group"); + return; + } + + char *endptr; + unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[2].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("add_group"); + return; + } + + try { + commandParser->application->getUserManager()->addGroup(Common::GroupInfo(gid, args[2])); + + std::cout << "Group added." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + +void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::vector &args) { + if(args.size() < 4) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("update_group"); + return; + } + if(args.size() > 4) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("update_group"); + return; + } + + char *endptr; + unsigned long origGid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse the old group id." << std::endl; + commandParser->printUsage("update_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 the new group id." << std::endl; + commandParser->printUsage("update_group"); + return; + } + + try { + commandParser->application->getUserManager()->updateGroup(origGid, Common::GroupInfo(gid, args[3])); + + std::cout << "Group updated." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + +void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::vector &args) { + if(args.size() < 2) { + std::cerr << args[0] << ": No group id given." << std::endl; + commandParser->printUsage("delete_group"); + return; + } + if(args.size() > 2) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("delete_group"); + return; + } + + char *endptr; + unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("delete_group"); + return; + } + + try { + commandParser->application->getUserManager()->deleteGroup(gid); + + std::cout << "Group deleted." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() < 3) { std::cerr << args[0] << ": Too few arguments." << std::endl; -- cgit v1.2.3