From 248bead428c626031ee6af37ff9de986d5536d68 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 3 Jun 2019 14:21:09 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9A=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D0=B0=20GetUserPassword=20=D0=BC=D0=B5=D0=BD=D1=8F=D1=8E?= =?UTF-8?q?=D1=89=D0=B0=D1=8F=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/dao/GetUserCommand.java | 2 +- .../command/dao/RegisterCommand.java | 2 + .../command/dao/SetUserPasswordCommand.java | 37 +++++++++++++++++++ .../command/handler/CommandHandler.java | 2 + 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java index 0a476411..0cdae071 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java @@ -26,7 +26,7 @@ public void invoke(String... args) throws Exception { User user = server.userService.findUserByUsername(args[0]); if(user == null) { - LogHelper.error("User %s not found", args[1]); + LogHelper.error("User %s not found", args[0]); return; } LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString()); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java index 83e0f5b3..61585116 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java @@ -3,6 +3,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.dao.User; +import pro.gravit.utils.helper.LogHelper; import java.util.UUID; @@ -29,5 +30,6 @@ public void invoke(String... args) throws Exception { user.setPassword(args[1]); user.uuid = UUID.randomUUID(); LaunchServer.server.userService.saveUser(user); + LogHelper.info("User %s registered. UUID: %s", user.username, user.uuid.toString()); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java new file mode 100644 index 00000000..e0b38d9c --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java @@ -0,0 +1,37 @@ +package pro.gravit.launchserver.command.dao; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.launchserver.dao.User; +import pro.gravit.utils.helper.LogHelper; + +public class SetUserPasswordCommand extends Command { + + public SetUserPasswordCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[username] [new password]"; + } + + @Override + public String getUsageDescription() { + return "Set user password"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 2); + User user = server.userService.findUserByUsername(args[0]); + if(user == null) + { + LogHelper.error("User %s not found", args[1]); + return; + } + user.setPassword(args[1]); + server.userService.updateUser(user); + LogHelper.info("[%s] UUID: %s | New Password: %s", user.username, user.uuid.toString(), args[1]); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index bf1f76bf..ca7e4453 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -5,6 +5,7 @@ import pro.gravit.launchserver.command.dao.GetAllUsersCommand; import pro.gravit.launchserver.command.dao.GetUserCommand; import pro.gravit.launchserver.command.dao.RegisterCommand; +import pro.gravit.launchserver.command.dao.SetUserPasswordCommand; import pro.gravit.launchserver.command.hash.*; import pro.gravit.launchserver.command.install.CheckInstallCommand; import pro.gravit.launchserver.command.install.MultiCommand; @@ -63,6 +64,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand //Register dao commands BaseCommandCategory dao = new BaseCommandCategory(); dao.registerCommand("register", new RegisterCommand(server)); + dao.registerCommand("setUserPassword", new SetUserPasswordCommand(server)); dao.registerCommand("getUser", new GetUserCommand(server)); dao.registerCommand("getAllUsers", new GetAllUsersCommand(server)); Category daoCategory = new Category(dao, "DAO", "Data Management");