mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-10-31 07:39:42 +01:00
Merge pull request #1458 from AuthMe/1435-send-recovery-email-in-async
#1435 Send password recovery emails in async
This commit is contained in:
commit
c1f3fcd393
@ -7,6 +7,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceResult;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
@ -39,6 +40,9 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private RecoveryCodeService recoveryCodeService;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
protected void runCommand(Player player, List<String> arguments) {
|
||||
final String playerMail = arguments.get(0);
|
||||
@ -66,13 +70,15 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recoveryCodeService.isRecoveryCodeNeeded()) {
|
||||
// Recovery code is needed; generate and send one
|
||||
recoveryService.createAndSendRecoveryCode(player, email);
|
||||
} else {
|
||||
// Code not needed, just send them a new password
|
||||
recoveryService.generateAndSendNewPassword(player, email);
|
||||
}
|
||||
bukkitService.runTaskAsynchronously(() -> {
|
||||
if (recoveryCodeService.isRecoveryCodeNeeded()) {
|
||||
// Recovery code is needed; generate and send one
|
||||
recoveryService.createAndSendRecoveryCode(player, email);
|
||||
} else {
|
||||
// Code not needed, just send them a new password
|
||||
recoveryService.generateAndSendNewPassword(player, email);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import fr.xephi.authme.datasource.DataSourceResult;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
@ -22,6 +23,7 @@ import org.mockito.Mock;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskAsynchronously;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@ -63,6 +65,9 @@ public class RecoverEmailCommandTest {
|
||||
@Mock
|
||||
private RecoveryCodeService recoveryCodeService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
@ -179,6 +184,7 @@ public class RecoverEmailCommandTest {
|
||||
String code = "a94f37";
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||
given(recoveryCodeService.generateCode(name)).willReturn(code);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(email.toUpperCase()));
|
||||
@ -201,6 +207,7 @@ public class RecoverEmailCommandTest {
|
||||
String email = "vulture@example.com";
|
||||
given(dataSource.getEmail(name)).willReturn(DataSourceResult.of(email));
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(email));
|
||||
|
Loading…
Reference in New Issue
Block a user