If recovery code is required, dont send new password
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
@@ -20,9 +18,6 @@ public class ProcessCodeCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private CommonService commonService;
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private RecoveryCodeService codeService;
|
||||
|
||||
@@ -36,14 +31,8 @@ public class ProcessCodeCommand extends PlayerCommand {
|
||||
|
||||
if (codeService.hasTriesLeft(name)) {
|
||||
if (codeService.isCodeValid(name, code)) {
|
||||
PlayerAuth auth = dataSource.getAuth(name);
|
||||
String email = auth.getEmail();
|
||||
if (email == null || "your@email.com".equalsIgnoreCase(email)) {
|
||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
recoveryService.generateAndSendNewPassword(player, email);
|
||||
commonService.send(player, MessageKey.RECOVERY_CODE_CORRECT);
|
||||
recoveryService.addSuccessfulRecovery(player);
|
||||
codeService.removeCode(name);
|
||||
} else {
|
||||
commonService.send(player, MessageKey.INCORRECT_RECOVERY_CODE,
|
||||
|
||||
@@ -66,9 +66,10 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
if (recoveryCodeService.isRecoveryCodeNeeded()) {
|
||||
// Process /email recovery addr@example.com
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,9 @@ public enum MessageKey {
|
||||
/** You have exceeded the maximum number of attempts to enter the recovery code. Use "/email recovery [email]" to generate a new one. */
|
||||
RECOVERY_TRIES_EXCEEDED("recovery_tries_exceeded"),
|
||||
|
||||
/** Recovery code entered correctly! */
|
||||
RECOVERY_CODE_CORRECT("recovery_code_correct"),
|
||||
|
||||
/** Please use the command /email setpassword to change your password immediately. */
|
||||
RECOVERY_CHANGE_PASSWORD("recovery_change_password"),
|
||||
|
||||
|
||||
@@ -101,16 +101,25 @@ public class PasswordRecoveryService implements Reloadable {
|
||||
if (couldSendMail) {
|
||||
commonService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
||||
emailCooldown.add(player.getName().toLowerCase());
|
||||
|
||||
String address = PlayerUtils.getPlayerIp(player);
|
||||
|
||||
successfulRecovers.put(name, address);
|
||||
commonService.send(player, MessageKey.RECOVERY_CHANGE_PASSWORD);
|
||||
} else {
|
||||
commonService.send(player, MessageKey.EMAIL_SEND_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a player to change their password after
|
||||
* correctly entering a recovery code.
|
||||
*
|
||||
* @param player The player recovering their password.
|
||||
*/
|
||||
public void addSuccessfulRecovery(Player player) {
|
||||
String name = player.getName();
|
||||
String address = PlayerUtils.getPlayerIp(player);
|
||||
|
||||
successfulRecovers.put(name, address);
|
||||
commonService.send(player, MessageKey.RECOVERY_CHANGE_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player is able to have emails sent.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user