Implemented the captcha command, fixed permissions for email commands

Implemented the captcha command.
Fixed missing permission configurations for all email commands.
This commit is contained in:
Tim Visée 2015-11-01 21:36:56 +01:00
parent 3e16866b23
commit bd6a95c3a8
3 changed files with 118 additions and 1 deletions

View File

@ -353,7 +353,7 @@ public class AuthMe extends JavaPlugin {
//getCommand("logout").setExecutor(new LogoutCommand(this));
//getCommand("unregister").setExecutor(new UnregisterCommand(this));
//getCommand("email").setExecutor(new EmailCommand(this));
getCommand("captcha").setExecutor(new CaptchaCommand(this));
//getCommand("captcha").setExecutor(new CaptchaCommand(this));
getCommand("converter").setExecutor(new ConverterCommand(this));
// Purge on start if enabled

View File

@ -496,6 +496,7 @@ public class CommandManager {
"Add E-mail",
"Add an new E-Mail address to your account.",
emailBaseCommand);
addEmailCommand.setCommandPermissions("authme.email.add", CommandPermissions.DefaultPermission.ALLOWED);
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
@ -510,6 +511,7 @@ public class CommandManager {
"Change E-mail",
"Change an E-Mail address of your account.",
emailBaseCommand);
changeEmailCommand.setCommandPermissions("authme.email.change", CommandPermissions.DefaultPermission.ALLOWED);
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
@ -525,6 +527,7 @@ public class CommandManager {
"Recover using E-mail",
"Recover your account using an E-mail address.",
emailBaseCommand);
recoverEmailCommand.setCommandPermissions("authme.email.recover", CommandPermissions.DefaultPermission.ALLOWED);
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
// Register the help command
@ -543,6 +546,35 @@ public class CommandManager {
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
emailHelpCommand.setMaximumArguments(false);
// Register the base captcha command
CommandDescription captchaBaseCommand = new CommandDescription(
new ChangePasswordCommand(),
new ArrayList<String>() {{
add("captcha");
add("capt");
}},
"Captcha command",
"Captcha command for AuthMeReloaded.", null);
captchaBaseCommand.setCommandPermissions("authme.captcha", CommandPermissions.DefaultPermission.ALLOWED);
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
captchaBaseCommand.setMaximumArguments(false);
// Register the help command
CommandDescription captchaHelpCommand = new CommandDescription(
new HelpCommand(),
new ArrayList<String>() {{
add("help");
add("hlp");
add("h");
add("sos");
add("?");
}},
"View help",
"View detailed help pages about AuthMeReloaded change captcha commands.",
captchaBaseCommand);
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
captchaHelpCommand.setMaximumArguments(false);
// Add the base commands to the commands array
this.commandDescriptions.add(authMeBaseCommand);
this.commandDescriptions.add(loginBaseCommand);
@ -551,6 +583,7 @@ public class CommandManager {
this.commandDescriptions.add(unregisterBaseCommand);
this.commandDescriptions.add(changePasswordBaseCommand);
this.commandDescriptions.add(emailBaseCommand);
this.commandDescriptions.add(captchaBaseCommand);
}
/**

View File

@ -0,0 +1,84 @@
package fr.xephi.authme.command.executable.captcha;
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.security.RandomString;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CaptchaCommand extends ExecutableCommand {
/**
* RandomString instance, for captcha generation.
*/
public static RandomString randStr = new RandomString(Settings.captchaLength);
/**
* 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 parameter values
String captcha = commandArguments.get(0);
// Make sure the current command executor is a player
if(!(sender instanceof Player)) {
return true;
}
// Get the player instance and name
final Player player = (Player) sender;
final String playerNameLowerCase = player.getName().toLowerCase();
// Command logic
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
m.send(player, "logged_in");
return true;
}
if (!Settings.useCaptcha) {
m.send(player, "usage_log");
return true;
}
if (!plugin.cap.containsKey(playerNameLowerCase)) {
m.send(player, "usage_log");
return true;
}
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
plugin.cap.remove(playerNameLowerCase);
plugin.cap.put(playerNameLowerCase, randStr.nextString());
for (String s : m.send("wrong_captcha")) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
}
return true;
}
try {
plugin.captcha.remove(playerNameLowerCase);
plugin.cap.remove(playerNameLowerCase);
} catch (NullPointerException ignored) { }
// Show a status message
m.send(player, "valid_captcha");
m.send(player, "login_msg");
return true;
}
}