Email verification code (#1382)

* Base verification code implementation, must define command, manager, events
* VerificationManager, verification command and messages, handled some sensible commands, configuration values
* Improved manager and sensible commands trigger
* Updated messages
* Updated verification code manager, fixed tests
* Switched to a permission based command
* Verification manager and command improved and added tests
* Edited messages
This commit is contained in:
HexelDev
2017-10-28 12:23:14 +02:00
committed by ljacqu
parent 8422581a82
commit ba65633182
58 changed files with 1227 additions and 67 deletions
@@ -67,7 +67,7 @@ public class EmailService {
File file = null;
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
try {
file = generateImage(name, newPass);
file = generatePasswordImage(name, newPass);
mailText = embedImageIntoEmailContent(file, email, mailText);
} catch (IOException | EmailException e) {
ConsoleLogger.logException(
@@ -80,6 +80,33 @@ public class EmailService {
return couldSendEmail;
}
/**
* Sends an email to the user with the temporary verification code.
*
* @param name the name of the player
* @param mailAddress the player's email
* @param code the verification code
* @return true if email could be sent, false otherwise
*/
public boolean sendVerificationMail(String name, String mailAddress, String code) {
if (!hasAllInformation()) {
ConsoleLogger.warning("Cannot send verification email: not all email settings are complete");
return false;
}
HtmlEmail email;
try {
email = sendMailSsl.initializeMail(mailAddress);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create verification email with the given settings:", e);
return false;
}
String mailText = replaceTagsForVerificationEmail(settings.getVerificationEmailMessage(), name, code,
settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES));
return sendMailSsl.sendEmail(mailText, email);
}
/**
* Sends an email to the user with a recovery code for the password recovery process.
*
@@ -102,7 +129,7 @@ public class EmailService {
return sendMailSsl.sendEmail(message, htmlEmail);
}
private File generateImage(String name, String newPass) throws IOException {
private File generatePasswordImage(String name, String newPass) throws IOException {
ImageGenerator gen = new ImageGenerator(newPass);
File file = new File(dataFolder, name + "_new_pass.jpg");
ImageIO.write(gen.generateImage(), "jpg", file);
@@ -123,6 +150,14 @@ public class EmailService {
.replace("<generatedpass />", newPass);
}
private String replaceTagsForVerificationEmail(String mailText, String name, String code, int minutesValid) {
return mailText
.replace("<playername />", name)
.replace("<servername />", serverName)
.replace("<generatedcode />", code)
.replace("<minutesvalid />", String.valueOf(minutesValid));
}
private String replaceTagsForRecoveryCodeMail(String mailText, String name, String code, int hoursValid) {
return mailText
.replace("<playername />", name)