diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-08-07 00:12:52 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-08-07 00:12:52 +0200 |
commit | 758f3cf98f95fc906c2517c0d4537ce81cf7386d (patch) | |
tree | 7e3afe4df48961a509cc25196d1bc6bb7d3ee28f /src/Client/UserCommands.cpp | |
parent | 94c00010a0280b8adc220377916a65b8dba08b62 (diff) | |
download | mad-758f3cf98f95fc906c2517c0d4537ce81cf7386d.tar mad-758f3cf98f95fc906c2517c0d4537ce81cf7386d.zip |
UserBackendMysql, client: Added group administration
Diffstat (limited to 'src/Client/UserCommands.cpp')
-rw-r--r-- | src/Client/UserCommands.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
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<std::string> &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<std::string> &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<std::string> &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<std::string> &args) { if(args.size() < 3) { std::cerr << args[0] << ": Too few arguments." << std::endl; |