From c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 7 Jul 2009 18:51:35 +0200 Subject: Added add_user command to client & UserBackendMysql --- src/Client/UserCommands.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/Client/UserCommands.cpp') diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index fec2a33..9fcaa36 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -17,6 +17,8 @@ * with this program. If not, see . */ +#include + #include "UserCommands.h" #include "Application.h" #include "CommandParser.h" @@ -221,5 +223,46 @@ void UserCommands::listGroupUsersCommand(CommandParser *commandParser, const std } } +void UserCommands::addUserCommand(CommandParser *commandParser, const std::vector &args) { + if(args.size() < 5) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("add_user"); + return; + } + if(args.size() > 5) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("add_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("add_user"); + 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"); + return; + } + + try { + Common::UserInfo user(uid, args[3]); + user.setGid(gid); + user.setFullName(args[4]); + + commandParser->application->getUserManager()->addUser(user); + + std::cout << "User added." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + } } -- cgit v1.2.3