Merge pull request #1547 from AuthMe/ip-check

[Discussion] Skip IP check for API registration
This commit is contained in:
ljacqu 2018-07-16 19:24:14 +02:00 committed by GitHub
commit c420255ad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,7 @@ public class AsyncRegister implements AsynchronousProcess {
* @param <P> parameters type * @param <P> parameters type
*/ */
public <P extends RegistrationParameters> void register(RegistrationMethod<P> variant, P parameters) { public <P extends RegistrationParameters> void register(RegistrationMethod<P> variant, P parameters) {
if (preRegisterCheck(parameters.getPlayer())) { if (preRegisterCheck(variant, parameters.getPlayer())) {
RegistrationExecutor<P> executor = registrationExecutorFactory.getSingleton(variant.getExecutorClass()); RegistrationExecutor<P> executor = registrationExecutorFactory.getSingleton(variant.getExecutorClass());
if (executor.isRegistrationAdmitted(parameters)) { if (executor.isRegistrationAdmitted(parameters)) {
executeRegistration(parameters, executor); executeRegistration(parameters, executor);
@ -65,11 +65,12 @@ public class AsyncRegister implements AsynchronousProcess {
/** /**
* Checks if the player is able to register, in that case the {@link AuthMeAsyncPreRegisterEvent} is invoked. * Checks if the player is able to register, in that case the {@link AuthMeAsyncPreRegisterEvent} is invoked.
* *
* @param variant the registration type variant.
* @param player the player which is trying to register. * @param player the player which is trying to register.
* *
* @return true if the checks are successful and the event hasn't marked the action as denied, false otherwise. * @return true if the checks are successful and the event hasn't marked the action as denied, false otherwise.
*/ */
private boolean preRegisterCheck(Player player) { private boolean preRegisterCheck(RegistrationMethod<?> variant, Player player) {
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
if (playerCache.isAuthenticated(name)) { if (playerCache.isAuthenticated(name)) {
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
@ -88,7 +89,7 @@ public class AsyncRegister implements AsynchronousProcess {
return false; return false;
} }
return isPlayerIpAllowedToRegister(player); return variant == RegistrationMethod.API_REGISTRATION || isPlayerIpAllowedToRegister(player);
} }
/** /**