#655 Encapsulate mail service

- Change SendMailSSL to be injected into classes and created regardless of settings
- Various minor cleanups (remove accidentally committed test, add more precise logging statement)
This commit is contained in:
ljacqu
2016-07-02 20:56:53 +02:00
parent d2556b8a04
commit 9a5c432509
9 changed files with 80 additions and 72 deletions
@@ -75,7 +75,7 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
if (dataSource.updatePassword(auth)) {
commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
ConsoleLogger.info(playerNameLowerCase + "'s password changed");
ConsoleLogger.info(sender.getName() + " changed password of " + playerNameLowerCase);
} else {
commandService.send(sender, MessageKey.ERROR);
}
@@ -1,12 +1,12 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
@@ -33,15 +33,14 @@ public class RecoverEmailCommand extends PlayerCommand {
private PlayerCache playerCache;
@Inject
// TODO #655: Remove injected AuthMe instance once Authme#mail is encapsulated
private AuthMe plugin;
private SendMailSSL sendMailSsl;
@Override
public void runCommand(Player player, List<String> arguments) {
final String playerMail = arguments.get(0);
final String playerName = player.getName();
if (plugin.getMail() == null) {
if (!sendMailSsl.hasAllInformation()) {
ConsoleLogger.showError("Mail API is not set");
commandService.send(player, MessageKey.ERROR);
return;
@@ -76,7 +75,7 @@ public class RecoverEmailCommand extends PlayerCommand {
}
auth.setPassword(hashNew);
dataSource.updatePassword(auth);
plugin.getMail().main(auth, thePass);
sendMailSsl.sendPasswordMail(auth, thePass);
commandService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
} else {
commandService.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
@@ -3,6 +3,7 @@ package fr.xephi.authme.command.executable.register;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.HashAlgorithm;
@@ -27,6 +28,9 @@ public class RegisterCommand extends PlayerCommand {
@Inject
private CommandService commandService;
@Inject
private SendMailSSL sendMailSsl;
@Override
public void runCommand(Player player, List<String> arguments) {
if (commandService.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) {
@@ -63,11 +67,11 @@ public class RegisterCommand extends PlayerCommand {
}
private void handleEmailRegistration(Player player, List<String> arguments) {
if (commandService.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) {
player.sendMessage("Cannot register: no email address is set for the server. "
if (!sendMailSsl.hasAllInformation()) {
player.sendMessage("Cannot register: not all required settings are set for sending emails. "
+ "Please contact an administrator");
ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email is set "
+ "to send emails from. Please add one in your config at " + EmailSettings.MAIL_ACCOUNT.getPath());
ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email or password is set "
+ "to send emails from. Please adjust your config at " + EmailSettings.MAIL_ACCOUNT.getPath());
return;
}