#567 Add/change email should be aware of account threshold

This commit is contained in:
ljacqu
2016-04-03 14:24:12 +02:00
parent 88e517635c
commit b6ccb3e632
15 changed files with 60 additions and 139 deletions
@@ -39,19 +39,8 @@ public class CommandService {
private final AntiBot antiBot;
private final ValidationService validationService;
/**
/*
* Constructor.
*
* @param authMe The plugin instance
* @param commandMapper Command mapper
* @param helpProvider Help provider
* @param messages Messages instance
* @param passwordSecurity The Password Security instance
* @param permissionsManager The permissions manager
* @param settings The settings manager
* @param ipAddressManager The IP address manager
* @param pluginHooks The plugin hooks instance
* @param spawnLoader The spawn loader
*/
public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
PasswordSecurity passwordSecurity, PermissionsManager permissionsManager, NewSetting settings,
@@ -4,7 +4,9 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.util.Utils;
import org.bukkit.command.CommandSender;
@@ -29,18 +31,20 @@ public class SetEmailCommand implements ExecutableCommand {
@Override
public void run() {
// Validate the user
PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
DataSource dataSource = commandService.getDataSource();
PlayerAuth auth = dataSource.getAuth(playerName);
if (auth == null) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
return;
} else if (commandService.getDataSource().isEmailStored(playerEmail)) {
} else if (dataSource.countAuthsByEmail(playerEmail)
>= commandService.getProperty(EmailSettings.MAX_REG_PER_EMAIL)) {
commandService.send(sender, MessageKey.EMAIL_ALREADY_USED_ERROR);
return;
}
// Set the email address
auth.setEmail(playerEmail);
if (!commandService.getDataSource().updateEmail(auth)) {
if (!dataSource.updateEmail(auth)) {
commandService.send(sender, MessageKey.ERROR);
return;
}
@@ -1,6 +1,7 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
@@ -9,7 +10,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.entity.Player;
@@ -19,13 +20,12 @@ public class RecoverEmailCommand extends PlayerCommand {
@Override
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
String playerMail = arguments.get(0);
final String playerMail = arguments.get(0);
final String playerName = player.getName();
// Command logic
final AuthMe plugin = AuthMe.getInstance();
final AuthMe plugin = commandService.getAuthMe();
if (plugin.mail == null) {
ConsoleLogger.showError("Mail API is not set");
commandService.send(player, MessageKey.ERROR);
return;
}
@@ -36,7 +36,7 @@ public class RecoverEmailCommand extends PlayerCommand {
return;
}
String thePass = RandomString.generate(Settings.getRecoveryPassLength);
String thePass = RandomString.generate(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH));
HashedPassword hashNew = commandService.getPasswordSecurity().computeHash(thePass, playerName);
PlayerAuth auth;
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
@@ -47,13 +47,14 @@ public class RecoverEmailCommand extends PlayerCommand {
commandService.send(player, MessageKey.UNKNOWN_USER);
return;
}
if (StringUtils.isEmpty(Settings.getmailAccount)) {
if (StringUtils.isEmpty(commandService.getProperty(EmailSettings.MAIL_ACCOUNT))) {
ConsoleLogger.showError("No mail account set in settings");
commandService.send(player, MessageKey.ERROR);
return;
}
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com")
|| auth.getEmail().equalsIgnoreCase("your@email.com")) {
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || "your@email.com".equalsIgnoreCase(playerMail)
|| "your@email.com".equalsIgnoreCase(auth.getEmail())) {
commandService.send(player, MessageKey.INVALID_EMAIL);
return;
}