#830 Refactor registration process
- Introduce registration executors: one for each registration variant; each extending class implements one registration variant and worries about that method's details only - AsyncRegister receives the player and a registration executor
This commit is contained in:
@@ -5,6 +5,7 @@ import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.process.register.executors.RegistrationExecutorProvider;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
@@ -12,13 +13,12 @@ import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType.Execution;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.RandomStringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.EMAIL_WITH_CONFIRMATION;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_EMAIL;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTRATION_TYPE;
|
||||
@@ -40,11 +40,15 @@ public class RegisterCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
private RegistrationExecutorProvider registrationExecutorProvider;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
if (commonService.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) {
|
||||
//for two factor auth we don't need to check the usage
|
||||
management.performRegister(player, "", "", true);
|
||||
management.performRegister(player,
|
||||
registrationExecutorProvider.getTwoFactorRegisterExecutor(player));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,12 +75,20 @@ public class RegisterCommand extends PlayerCommand {
|
||||
RegistrationArgumentType registrationType = commonService.getProperty(REGISTRATION_TYPE);
|
||||
if (registrationType == PASSWORD_WITH_CONFIRMATION && !arguments.get(0).equals(arguments.get(1))) {
|
||||
commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
} else if (registrationType == PASSWORD_WITH_EMAIL && !validationService.validateEmail(arguments.get(1))) {
|
||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else if (registrationType == PASSWORD_WITH_EMAIL) {
|
||||
handlePasswordWithEmailRegistration(player, arguments);
|
||||
} else {
|
||||
// We might only have received one argument, need to check that it's safe to do arguments.get(1)
|
||||
String email = registrationType == PASSWORD_WITH_EMAIL ? arguments.get(1) : null;
|
||||
management.performRegister(player, arguments.get(0), email, true);
|
||||
management.performRegister(player, registrationExecutorProvider
|
||||
.getPasswordRegisterExecutor(player, arguments.get(0)));
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePasswordWithEmailRegistration(Player player, List<String> arguments) {
|
||||
if (validationService.validateEmail(arguments.get(1))) {
|
||||
management.performRegister(player, registrationExecutorProvider
|
||||
.getPasswordRegisterExecutor(player, arguments.get(0), arguments.get(1)));
|
||||
} else {
|
||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,12 +103,10 @@ public class RegisterCommand extends PlayerCommand {
|
||||
final String email = arguments.get(0);
|
||||
if (!validationService.validateEmail(email)) {
|
||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else if (commonService.getProperty(REGISTRATION_TYPE) == RegistrationArgumentType.EMAIL_WITH_CONFIRMATION
|
||||
&& !email.equals(arguments.get(1))) {
|
||||
} else if (commonService.getProperty(REGISTRATION_TYPE) == EMAIL_WITH_CONFIRMATION && !email.equals(arguments.get(1))) {
|
||||
commonService.send(player, MessageKey.USAGE_REGISTER);
|
||||
} else {
|
||||
String thePass = RandomStringUtils.generate(commonService.getProperty(RECOVERY_PASSWORD_LENGTH));
|
||||
management.performRegister(player, thePass, email, true);
|
||||
management.performRegister(player, registrationExecutorProvider.getEmailRegisterExecutor(player, email));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user