#472 Require recovery code before resetting password
- /email recovery generates recovery code and resets password only if recovery code is also given - Change data source method to return email and recovery code
This commit is contained in:
@@ -2,7 +2,6 @@ package fr.xephi.authme.mail;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
@@ -53,16 +52,17 @@ public class SendMailSSL {
|
||||
/**
|
||||
* Sends an email to the user with his new password.
|
||||
*
|
||||
* @param auth the player auth of the player
|
||||
* @param name the name of the player
|
||||
* @param mailAddress the player's email
|
||||
* @param newPass the new password
|
||||
*/
|
||||
public void sendPasswordMail(final PlayerAuth auth, final String newPass) {
|
||||
public void sendPasswordMail(String name, String mailAddress, String newPass) {
|
||||
if (!hasAllInformation()) {
|
||||
ConsoleLogger.warning("Cannot perform email registration: not all email settings are complete");
|
||||
return;
|
||||
}
|
||||
|
||||
final String mailText = replaceMailTags(settings.getEmailMessage(), auth, newPass);
|
||||
final String mailText = replaceMailTags(settings.getEmailMessage(), name, newPass);
|
||||
bukkitService.runTaskAsynchronously(new Runnable() {
|
||||
|
||||
@Override
|
||||
@@ -70,7 +70,7 @@ public class SendMailSSL {
|
||||
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||
HtmlEmail email;
|
||||
try {
|
||||
email = initializeMail(auth.getEmail());
|
||||
email = initializeMail(mailAddress);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email with the given settings:", e);
|
||||
return;
|
||||
@@ -81,11 +81,11 @@ public class SendMailSSL {
|
||||
File file = null;
|
||||
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
|
||||
try {
|
||||
file = generateImage(auth.getNickname(), plugin, newPass);
|
||||
file = generateImage(name, plugin, newPass);
|
||||
content = embedImageIntoEmailContent(file, email, content);
|
||||
} catch (IOException | EmailException e) {
|
||||
ConsoleLogger.logException(
|
||||
"Unable to send new password as image for email " + auth.getEmail() + ":", e);
|
||||
"Unable to send new password as image for email " + mailAddress + ":", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,20 @@ public class SendMailSSL {
|
||||
});
|
||||
}
|
||||
|
||||
public void sendRecoveryCode(String email, String code) {
|
||||
// TODO #472: Create a configurable, more verbose message
|
||||
String message = String.format("Use /email recovery %s %s to reset your password", email, code);
|
||||
|
||||
HtmlEmail htmlEmail;
|
||||
try {
|
||||
htmlEmail = initializeMail(email);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email for recovery code:", e);
|
||||
return;
|
||||
}
|
||||
sendEmail(message, htmlEmail);
|
||||
}
|
||||
|
||||
private static File generateImage(String name, AuthMe plugin, String newPass) throws IOException {
|
||||
ImageGenerator gen = new ImageGenerator(newPass);
|
||||
File file = new File(plugin.getDataFolder(), name + "_new_pass.jpg");
|
||||
@@ -149,9 +163,9 @@ public class SendMailSSL {
|
||||
}
|
||||
}
|
||||
|
||||
private String replaceMailTags(String mailText, PlayerAuth auth, String newPass) {
|
||||
private String replaceMailTags(String mailText, String name, String newPass) {
|
||||
return mailText
|
||||
.replace("<playername />", auth.getNickname())
|
||||
.replace("<playername />", name)
|
||||
.replace("<servername />", plugin.getServer().getServerName())
|
||||
.replace("<generatedpass />", newPass);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user