diff --git a/pom.xml b/pom.xml index 581affd1..230fd9f1 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ - The GNU General Public Licence version 3 (GPLv3) + The GNU Public Licence version 3 (GPLv3) https://www.gnu.org/licenses/gpl-3.0.html repo @@ -196,6 +196,11 @@ org.apache.maven.plugins maven-resources-plugin 3.3.0 + + + mmdb + + diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 045d1ee9..13f359e3 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -19,6 +19,7 @@ import fr.xephi.authme.listener.PlayerListener111; import fr.xephi.authme.listener.PlayerListener19; import fr.xephi.authme.listener.PlayerListener19Spigot; import fr.xephi.authme.listener.ServerListener; +import fr.xephi.authme.mail.EmailService; import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.security.crypts.Sha256; import fr.xephi.authme.service.BackupService; @@ -28,6 +29,7 @@ import fr.xephi.authme.service.bungeecord.BungeeReceiver; import fr.xephi.authme.service.yaml.YamlParseException; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SettingsWarner; +import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.task.CleanupTask; import fr.xephi.authme.task.purge.PurgeService; @@ -42,6 +44,8 @@ import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.scheduler.BukkitScheduler; import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.function.Consumer; import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE; @@ -65,6 +69,7 @@ public class AuthMe extends JavaPlugin { private CommandHandler commandHandler; private Settings settings; private DataSource database; + private EmailService emailService; private BukkitService bukkitService; private Injector injector; private BackupService backupService; @@ -308,6 +313,12 @@ public class AuthMe extends JavaPlugin { onShutdownPlayerSaver.saveAllPlayers(); } + if (settings.getProperty(EmailSettings.SHOUTDOWN_MAIL)){ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy'年'MM'月'dd'日' HH:mm:ss"); + Date date = new Date(System.currentTimeMillis()); + emailService.sendShutDown("wujiaxin752@icloud.com",dateFormat.format(date)); + } + // Do backup on stop if enabled if (backupService != null) { backupService.doBackup(BackupService.BackupCause.STOP); diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index 922e1104..53330fb3 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -5,6 +5,7 @@ import fr.xephi.authme.command.PlayerCommand; import fr.xephi.authme.data.captcha.RegistrationCaptchaManager; import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.mail.EmailService; +import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.process.Management; import fr.xephi.authme.process.register.RegisterSecondaryArgument; @@ -23,6 +24,8 @@ import org.bukkit.entity.Player; import javax.inject.Inject; import java.util.List; +import java.util.Timer; +import java.util.TimerTask; import static fr.xephi.authme.process.register.RegisterSecondaryArgument.CONFIRMATION; import static fr.xephi.authme.process.register.RegisterSecondaryArgument.EMAIL_MANDATORY; @@ -43,6 +46,9 @@ public class RegisterCommand extends PlayerCommand { @Inject private CommonService commonService; + @Inject + private DataSource dataSource; + @Inject private EmailService emailService; @@ -169,6 +175,22 @@ public class RegisterCommand extends PlayerCommand { } else if (isSecondArgValidForEmailRegistration(player, arguments)) { management.performRegister(RegistrationMethod.EMAIL_REGISTRATION, EmailRegisterParams.of(player, email)); + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + if (dataSource.getAuth(player.getName()) != null) { + if (dataSource.getAuth(player.getName()).getLastLogin() == null && (dataSource.getAuth(player.getName()).getRegistrationDate() + 600000) < System.currentTimeMillis()) { + management.performUnregisterByAdmin(null, player.getName(), player); + timer.cancel(); + } else if (dataSource.getAuth(player.getName()).getLastLogin() != null) { + timer.cancel(); + } + } else { + timer.cancel(); + } + } + }, 60000, 60000); } } diff --git a/src/main/java/fr/xephi/authme/data/VerificationCodeManager.java b/src/main/java/fr/xephi/authme/data/VerificationCodeManager.java index 0a8ff061..ad1b778d 100644 --- a/src/main/java/fr/xephi/authme/data/VerificationCodeManager.java +++ b/src/main/java/fr/xephi/authme/data/VerificationCodeManager.java @@ -15,6 +15,8 @@ import fr.xephi.authme.util.expiring.ExpiringMap; import org.bukkit.entity.Player; import javax.inject.Inject; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; @@ -132,12 +134,14 @@ public class VerificationCodeManager implements SettingsDependent, HasCleanup { */ private void generateCode(String name) { DataSourceValue emailResult = dataSource.getEmail(name); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy'年'MM'月'dd'日' HH:mm:ss"); + Date date = new Date(System.currentTimeMillis()); if (emailResult.rowExists()) { final String email = emailResult.getValue(); if (!Utils.isEmailEmpty(email)) { String code = RandomStringUtils.generateNum(6); // 6 digits code verificationCodes.put(name.toLowerCase(Locale.ROOT), code); - emailService.sendVerificationMail(name, email, code); + emailService.sendVerificationMail(name, email, code, dateFormat.format(date)); } } } diff --git a/src/main/java/fr/xephi/authme/mail/EmailService.java b/src/main/java/fr/xephi/authme/mail/EmailService.java index 6aef0433..0863f594 100644 --- a/src/main/java/fr/xephi/authme/mail/EmailService.java +++ b/src/main/java/fr/xephi/authme/mail/EmailService.java @@ -40,21 +40,7 @@ public class EmailService { return sendMailSsl.hasAllInformation(); } - - /** - * Sends an email to the user with his new password. - * - * @param name the name of the player - * @param mailAddress the player's email - * @param newPass the new password - * @return true if email could be sent, false otherwise - */ - public boolean sendPasswordMail(String name, String mailAddress, String newPass) { - if (!hasAllInformation()) { - logger.warning("Cannot perform email registration: not all email settings are complete"); - return false; - } - + public boolean sendNewPasswordMail(String name, String mailAddress, String newPass,String ip,String time) { HtmlEmail email; try { email = sendMailSsl.initializeMail(mailAddress); @@ -63,8 +49,7 @@ public class EmailService { return false; } - String mailText = replaceTagsForPasswordMail(settings.getPasswordEmailMessage(), name, newPass); - // Generate an image? + String mailText = replaceTagsForPasswordMail(settings.getNewPasswordEmailMessage(), name, newPass,ip,time); File file = null; if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) { try { @@ -82,16 +67,16 @@ public class EmailService { } /** - * Sends an email to the user with the temporary verification code. + * Sends an email to the user with his new password. * * @param name the name of the player * @param mailAddress the player's email - * @param code the verification code + * @param newPass the new password * @return true if email could be sent, false otherwise */ - public boolean sendVerificationMail(String name, String mailAddress, String code) { + public boolean sendPasswordMail(String name, String mailAddress, String newPass, String time) { if (!hasAllInformation()) { - logger.warning("Cannot send verification email: not all email settings are complete"); + logger.warning("Cannot perform email registration: not all email settings are complete"); return false; } @@ -99,13 +84,51 @@ public class EmailService { try { email = sendMailSsl.initializeMail(mailAddress); } catch (EmailException e) { - logger.logException("Failed to create verification email with the given settings:", e); + logger.logException("Failed to create email with the given settings:", e); return false; } + String mailText = replaceTagsForPasswordMail(settings.getPasswordEmailMessage(), name, newPass,time); + // Generate an image? + File file = null; + if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) { + try { + file = generatePasswordImage(name, newPass); + mailText = embedImageIntoEmailContent(file, email, mailText); + } catch (IOException | EmailException e) { + logger.logException( + "Unable to send new password as image for email " + mailAddress + ":", e); + } + } + + boolean couldSendEmail = sendMailSsl.sendEmail(mailText, email); + FileUtils.delete(file); + 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 + */ + public void sendVerificationMail(String name, String mailAddress, String code, String time) { + if (!hasAllInformation()) { + logger.warning("Cannot send verification email: not all email settings are complete"); + return; + } + + HtmlEmail email; + try { + email = sendMailSsl.initializeMail(mailAddress); + } catch (EmailException e) { + logger.logException("Failed to create verification email with the given settings:", e); + return; + } + String mailText = replaceTagsForVerificationEmail(settings.getVerificationEmailMessage(), name, code, - settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES)); - return sendMailSsl.sendEmail(mailText, email); + settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES),time); + sendMailSsl.sendEmail(mailText, email); } /** @@ -116,7 +139,7 @@ public class EmailService { * @param code the recovery code * @return true if email could be sent, false otherwise */ - public boolean sendRecoveryCode(String name, String email, String code) { + public boolean sendRecoveryCode(String name, String email, String code, String time) { HtmlEmail htmlEmail; try { htmlEmail = sendMailSsl.initializeMail(email); @@ -126,10 +149,23 @@ public class EmailService { } String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(), - name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)); + name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID),time); return sendMailSsl.sendEmail(message, htmlEmail); } + public void sendShutDown(String email, String time) { + HtmlEmail htmlEmail; + try { + htmlEmail = sendMailSsl.initializeMail(email); + } catch (EmailException e) { + logger.logException("Failed to create email for recovery code:", e); + return; + } + + String message = replaceTagsForShutDownMail(settings.getShutdownEmailMessage(), time); + sendMailSsl.sendEmail(message, htmlEmail); + } + private File generatePasswordImage(String name, String newPass) throws IOException { ImageGenerator gen = new ImageGenerator(newPass); File file = new File(dataFolder, name + "_new_pass.jpg"); @@ -144,26 +180,44 @@ public class EmailService { return content.replace("", ""); } - private String replaceTagsForPasswordMail(String mailText, String name, String newPass) { + private String replaceTagsForPasswordMail(String mailText, String name, String newPass,String ip,String time) { return mailText .replace("", name) .replace("", settings.getProperty(PluginSettings.SERVER_NAME)) - .replace("", newPass); + .replace("", newPass) + .replace("", ip) + .replace("