summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-07 18:51:35 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-07 18:51:35 +0200
commitc4cbe4a94fd63e0da6e291a481b9a9ccc71e7843 (patch)
tree54fc3c43aec1b08f6918add662574b35a355e363 /src/Client
parentf2f1d5b1da4f985bcbb0c075cf42efcacecae2a6 (diff)
downloadmad-c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843.tar
mad-c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843.zip
Added add_user command to client & UserBackendMysql
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp3
-rw-r--r--src/Client/UserCommands.cpp43
-rw-r--r--src/Client/UserCommands.h2
3 files changed, 48 insertions, 0 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 842be7f..92b1169 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -17,6 +17,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include "CommandParser.h"
#include "Application.h"
#include "InformationManager.h"
@@ -49,6 +51,7 @@ const CommandParser::Command CommandParser::commands[] = {
{{"list_groups", "groups", 0}, "list_groups", "Show the user group database", "Show the user group database.", &UserCommands::listGroupsCommand},
{{"group_info", "group", 0}, "group_info gid|name", "Search for a group id", "Search for a group.", &UserCommands::groupInfoCommand},
{{"list_group_users", "group_users", 0}, "list_group_users gid", "List group's users", "List the users that are members of the group.", &UserCommands::listGroupUsersCommand},
+ {{"add_user", 0}, "add_user uid gid username full_name", "Add a new user", "Adds a new user with the given info to the account database.", &UserCommands::addUserCommand},
{{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Close the connection and quit the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
};
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 <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#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<std::string> &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;
+ }
+}
+
}
}
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index 0f56a40..6e184b0 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -40,6 +40,8 @@ class UserCommands {
static void listGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void groupInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void listGroupUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+
+ static void addUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
};
}