mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-10-31 07:39:42 +01:00
Implemented the changepassword command
This commit is contained in:
parent
5093e8ff78
commit
a36553f75f
@ -349,7 +349,7 @@ public class AuthMe extends JavaPlugin {
|
||||
//getCommand("authme").setExecutor(new AdminCommand(this));
|
||||
//getCommand("register").setExecutor(new RegisterCommand(this));
|
||||
//getCommand("login").setExecutor(new LoginCommand(this));
|
||||
getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
|
||||
//getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
|
||||
getCommand("logout").setExecutor(new LogoutCommand(this));
|
||||
getCommand("unregister").setExecutor(new UnregisterCommand(this));
|
||||
getCommand("email").setExecutor(new EmailCommand(this));
|
||||
|
@ -2,6 +2,8 @@ package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.command.executable.*;
|
||||
import fr.xephi.authme.command.executable.authme.*;
|
||||
import fr.xephi.authme.command.executable.changepassword.*;
|
||||
import fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand;
|
||||
import fr.xephi.authme.command.executable.login.LoginCommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -385,10 +387,41 @@ public class CommandManager {
|
||||
registerHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||
registerHelpCommand.setMaximumArguments(false);
|
||||
|
||||
// Register the base changepassword command
|
||||
CommandDescription changePasswordBaseCommand = new CommandDescription(
|
||||
new ChangePasswordCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("changepassword");
|
||||
add("changepass");
|
||||
}},
|
||||
"Change password command",
|
||||
"Command to change your password using AuthMeReloaded.", null);
|
||||
changePasswordBaseCommand.setCommandPermissions("authme.changepassword", CommandPermissions.DefaultPermission.ALLOWED);
|
||||
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||
changePasswordBaseCommand.setMaximumArguments(false);
|
||||
|
||||
// Register the help command
|
||||
CommandDescription changePasswordHelpCommand = new CommandDescription(
|
||||
new HelpCommand(),
|
||||
new ArrayList<String>() {{
|
||||
add("help");
|
||||
add("hlp");
|
||||
add("h");
|
||||
add("sos");
|
||||
add("?");
|
||||
}},
|
||||
"View help",
|
||||
"View detailed help pages about AuthMeReloaded register commands.",
|
||||
changePasswordBaseCommand);
|
||||
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||
changePasswordHelpCommand.setMaximumArguments(false);
|
||||
|
||||
// Add the base commands to the commands array
|
||||
this.commandDescriptions.add(authMeBaseCommand);
|
||||
this.commandDescriptions.add(loginBaseCommand);
|
||||
this.commandDescriptions.add(registerBaseCommand);
|
||||
this.commandDescriptions.add(changePasswordBaseCommand);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,74 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.ChangePasswordTask;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ChangePasswordCommand extends ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Get the passwords
|
||||
String playerPass = commandArguments.get(0);
|
||||
String playerPassVerify = commandArguments.get(1);
|
||||
|
||||
// Make sure the current command executor is a player
|
||||
if(!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the player instance and make sure it's authenticated
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName().toLowerCase();
|
||||
if (!PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
m.send(player, "not_logged_in");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure the password is allowed
|
||||
String playerPassLowerCase = playerPass.toLowerCase();
|
||||
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||
m.send(player, "password_error");
|
||||
return true;
|
||||
}
|
||||
if (playerPassLowerCase.equalsIgnoreCase(name)) {
|
||||
m.send(player, "password_error_nick");
|
||||
return true;
|
||||
}
|
||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||
m.send(player, "pass_len");
|
||||
return true;
|
||||
}
|
||||
if (!Settings.unsafePasswords.isEmpty()) {
|
||||
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||
m.send(player, "password_error_unsafe");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the password
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, playerPass, playerPassVerify));
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user