* #1523 Create admin commands to handle players' 2FA data - Create admin command to view if a player has enabled 2FA - Create admin command to disable 2FA for a specified player
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command to disable two-factor authentication for a user.
|
||||
*/
|
||||
public class TotpDisableAdminCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
String player = arguments.get(0);
|
||||
|
||||
PlayerAuth auth = dataSource.getAuth(player);
|
||||
if (auth == null) {
|
||||
messages.send(sender, MessageKey.UNKNOWN_USER);
|
||||
} else if (auth.getTotpKey() == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Player '" + player + "' does not have two-factor auth enabled");
|
||||
} else {
|
||||
removeTotpKey(sender, player);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeTotpKey(CommandSender sender, String player) {
|
||||
if (dataSource.removeTotpKey(player)) {
|
||||
sender.sendMessage("Disabled two-factor authentication successfully for '" + player + "'");
|
||||
ConsoleLogger.info(sender.getName() + " disable two-factor authentication for '" + player + "'");
|
||||
|
||||
Player onlinePlayer = bukkitService.getPlayerExact(player);
|
||||
if (onlinePlayer != null) {
|
||||
messages.send(onlinePlayer, MessageKey.TWO_FACTOR_REMOVED_SUCCESS);
|
||||
}
|
||||
} else {
|
||||
messages.send(sender, MessageKey.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command to see whether a user has enabled two-factor authentication.
|
||||
*/
|
||||
public class TotpViewStatusCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private Messages messages;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
String player = arguments.get(0);
|
||||
|
||||
PlayerAuth auth = dataSource.getAuth(player);
|
||||
if (auth == null) {
|
||||
messages.send(sender, MessageKey.UNKNOWN_USER);
|
||||
} else if (auth.getTotpKey() == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Player '" + player + "' does NOT have two-factor auth enabled");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Player '" + player + "' has enabled two-factor authentication");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user