#567 Move email validation logic to validation service
This commit is contained in:
@@ -6,12 +6,13 @@ 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Admin command for setting an email to an account.
|
||||
*/
|
||||
public class SetEmailCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
@@ -22,7 +23,7 @@ public class SetEmailCommand implements ExecutableCommand {
|
||||
final String playerEmail = arguments.get(1);
|
||||
|
||||
// Validate the email address
|
||||
if (!Utils.isEmailCorrect(playerEmail, commandService.getSettings())) {
|
||||
if (!commandService.validateEmail(playerEmail)) {
|
||||
commandService.send(sender, MessageKey.INVALID_EMAIL);
|
||||
return;
|
||||
}
|
||||
@@ -36,8 +37,7 @@ public class SetEmailCommand implements ExecutableCommand {
|
||||
if (auth == null) {
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
} else if (dataSource.countAuthsByEmail(playerEmail)
|
||||
>= commandService.getProperty(EmailSettings.MAX_REG_PER_EMAIL)) {
|
||||
} else if (!commandService.isEmailFreeForRegistration(playerEmail, sender)) {
|
||||
commandService.send(sender, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package fr.xephi.authme.command.executable.email;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command for setting an email to an account.
|
||||
*/
|
||||
public class AddEmailCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
@@ -15,9 +17,8 @@ public class AddEmailCommand extends PlayerCommand {
|
||||
String email = arguments.get(0);
|
||||
String emailConfirmation = arguments.get(1);
|
||||
|
||||
if (!Utils.isEmailCorrect(email, commandService.getSettings())) {
|
||||
commandService.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else if (email.equals(emailConfirmation)) {
|
||||
if (email.equals(emailConfirmation)) {
|
||||
// Closer inspection of the mail address handled by the async task
|
||||
commandService.getManagement().performAddEmail(player, email);
|
||||
} else {
|
||||
commandService.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
|
||||
|
||||
@@ -7,13 +7,16 @@ import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION;
|
||||
|
||||
public class RegisterCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
@@ -24,25 +27,27 @@ public class RegisterCommand extends PlayerCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arguments.isEmpty() || Settings.enablePasswordConfirmation && arguments.size() < 2) {
|
||||
if (arguments.isEmpty() || commandService.getProperty(ENABLE_PASSWORD_CONFIRMATION) && arguments.size() < 2) {
|
||||
commandService.send(player, MessageKey.USAGE_REGISTER);
|
||||
return;
|
||||
}
|
||||
|
||||
final Management management = commandService.getManagement();
|
||||
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
|
||||
if (Settings.doubleEmailCheck && arguments.size() < 2 || !arguments.get(0).equals(arguments.get(1))) {
|
||||
if (commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
&& !commandService.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) {
|
||||
boolean emailDoubleCheck = commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL);
|
||||
if (emailDoubleCheck && arguments.size() < 2 || !arguments.get(0).equals(arguments.get(1))) {
|
||||
commandService.send(player, MessageKey.USAGE_REGISTER);
|
||||
return;
|
||||
}
|
||||
|
||||
final String email = arguments.get(0);
|
||||
if (!Utils.isEmailCorrect(email, commandService.getSettings())) {
|
||||
if (!commandService.validateEmail(email)) {
|
||||
commandService.send(player, MessageKey.INVALID_EMAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
final String thePass = RandomString.generate(Settings.getRecoveryPassLength);
|
||||
final String thePass = RandomString.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH));
|
||||
management.performRegister(player, thePass, email);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user