diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index b359b2707..a0def6391 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -151,10 +151,11 @@ public class NewAPI { } /** - * Register a player with the given password. + * Register an OFFLINE/ONLINE player with the given password. * * @param playerName The player to register * @param password The password to register the player with + * * @return true if the player was registered successfully */ public boolean registerPlayer(String playerName, String password) { @@ -190,13 +191,24 @@ public class NewAPI { } /** - * Register a player with the given password. + * Force an ONLINE player to register. + * + * @param player The player to register + * @param password The password to use + * @param autoLogin Should the player be authenticated automatically after the registration? + */ + public void forceRegister(Player player, String password, boolean autoLogin) { + plugin.getManagement().performRegister(player, password, null, autoLogin); + } + + /** + * Register an ONLINE player with the given password. * * @param player The player to register * @param password The password to use */ public void forceRegister(Player player, String password) { - plugin.getManagement().performRegister(player, password, null); + forceRegister(player, password, true); } /** diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index d060c56bd..37e2100af 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -23,7 +23,7 @@ public class RegisterCommand extends PlayerCommand { public void runCommand(Player player, List arguments, CommandService commandService) { if (commandService.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) { //for two factor auth we don't need to check the usage - commandService.getManagement().performRegister(player, "", ""); + commandService.getManagement().performRegister(player, "", "", true); return; } @@ -50,7 +50,7 @@ public class RegisterCommand extends PlayerCommand { if (commandService.getProperty(ENABLE_PASSWORD_CONFIRMATION) && !arguments.get(0).equals(arguments.get(1))) { commandService.send(player, MessageKey.PASSWORD_MATCH_ERROR); } else { - commandService.getManagement().performRegister(player, arguments.get(0), ""); + commandService.getManagement().performRegister(player, arguments.get(0), "", true); } } @@ -70,7 +70,7 @@ public class RegisterCommand extends PlayerCommand { commandService.send(player, MessageKey.USAGE_REGISTER); } else { String thePass = RandomString.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH)); - commandService.getManagement().performRegister(player, thePass, email); + commandService.getManagement().performRegister(player, thePass, email, true); } } diff --git a/src/main/java/fr/xephi/authme/process/Management.java b/src/main/java/fr/xephi/authme/process/Management.java index 04a0f414b..cb3efa81b 100644 --- a/src/main/java/fr/xephi/authme/process/Management.java +++ b/src/main/java/fr/xephi/authme/process/Management.java @@ -44,8 +44,8 @@ public class Management { runTask(new AsynchronousLogout(player, plugin, dataSource, processService)); } - public void performRegister(final Player player, final String password, final String email) { - runTask(new AsyncRegister(player, password, email, plugin, dataSource, playerCache, processService)); + public void performRegister(final Player player, final String password, final String email, final boolean autoLogin) { + runTask(new AsyncRegister(player, password, email, plugin, dataSource, playerCache, processService, autoLogin)); } public void performUnregister(final Player player, final String password, final boolean force) { diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 5cacb1050..77171cd08 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -37,9 +37,10 @@ public class AsyncRegister implements Process { private final DataSource database; private final PlayerCache playerCache; private final ProcessService service; + private final boolean autoLogin; public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data, - PlayerCache playerCache, ProcessService service) { + PlayerCache playerCache, ProcessService service, boolean autoLogin) { this.player = player; this.password = password; this.name = player.getName().toLowerCase(); @@ -49,6 +50,7 @@ public class AsyncRegister implements Process { this.ip = Utils.getPlayerIp(player); this.playerCache = playerCache; this.service = service; + this.autoLogin = autoLogin; } private boolean preRegisterCheck() { @@ -150,7 +152,7 @@ public class AsyncRegister implements Process { return; } - if (!Settings.forceRegLogin) { + if (!Settings.forceRegLogin && autoLogin) { //PlayerCache.getInstance().addPlayer(auth); //database.setLogged(name); // TODO: check this... diff --git a/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java index 6f86a5f65..e5faa450f 100644 --- a/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java @@ -84,7 +84,7 @@ public class RegisterCommandTest { command.executeCommand(sender, Collections.emptyList(), commandService); // then - verify(management).performRegister(sender, "", ""); + verify(management).performRegister(sender, "", "", true); } @Test @@ -204,7 +204,7 @@ public class RegisterCommandTest { // then verify(commandService).validateEmail(playerMail); - verify(management).performRegister(eq(sender), argThat(stringWithLength(passLength)), eq(playerMail)); + verify(management).performRegister(eq(sender), argThat(stringWithLength(passLength)), eq(playerMail), true); } @Test @@ -230,7 +230,7 @@ public class RegisterCommandTest { command.executeCommand(sender, Collections.singletonList("myPass"), commandService); // then - verify(management).performRegister(sender, "myPass", ""); + verify(management).performRegister(sender, "myPass", "", true); }