[FEATURE] Команда GetUserPassword меняющая пароль пользователя

This commit is contained in:
Gravit 2019-06-03 14:21:09 +07:00
parent 952279b1f4
commit 248bead428
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 42 additions and 1 deletions

View file

@ -26,7 +26,7 @@ public void invoke(String... args) throws Exception {
User user = server.userService.findUserByUsername(args[0]); User user = server.userService.findUserByUsername(args[0]);
if(user == null) if(user == null)
{ {
LogHelper.error("User %s not found", args[1]); LogHelper.error("User %s not found", args[0]);
return; return;
} }
LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString()); LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString());

View file

@ -3,6 +3,7 @@
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.User;
import pro.gravit.utils.helper.LogHelper;
import java.util.UUID; import java.util.UUID;
@ -29,5 +30,6 @@ public void invoke(String... args) throws Exception {
user.setPassword(args[1]); user.setPassword(args[1]);
user.uuid = UUID.randomUUID(); user.uuid = UUID.randomUUID();
LaunchServer.server.userService.saveUser(user); LaunchServer.server.userService.saveUser(user);
LogHelper.info("User %s registered. UUID: %s", user.username, user.uuid.toString());
} }
} }

View file

@ -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]);
}
}

View file

@ -5,6 +5,7 @@
import pro.gravit.launchserver.command.dao.GetAllUsersCommand; import pro.gravit.launchserver.command.dao.GetAllUsersCommand;
import pro.gravit.launchserver.command.dao.GetUserCommand; import pro.gravit.launchserver.command.dao.GetUserCommand;
import pro.gravit.launchserver.command.dao.RegisterCommand; 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.hash.*;
import pro.gravit.launchserver.command.install.CheckInstallCommand; import pro.gravit.launchserver.command.install.CheckInstallCommand;
import pro.gravit.launchserver.command.install.MultiCommand; import pro.gravit.launchserver.command.install.MultiCommand;
@ -63,6 +64,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand
//Register dao commands //Register dao commands
BaseCommandCategory dao = new BaseCommandCategory(); BaseCommandCategory dao = new BaseCommandCategory();
dao.registerCommand("register", new RegisterCommand(server)); dao.registerCommand("register", new RegisterCommand(server));
dao.registerCommand("setUserPassword", new SetUserPasswordCommand(server));
dao.registerCommand("getUser", new GetUserCommand(server)); dao.registerCommand("getUser", new GetUserCommand(server));
dao.registerCommand("getAllUsers", new GetAllUsersCommand(server)); dao.registerCommand("getAllUsers", new GetAllUsersCommand(server));
Category daoCategory = new Category(dao, "DAO", "Data Management"); Category daoCategory = new Category(dao, "DAO", "Data Management");