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