#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:
parent
d2556b8a04
commit
9a5c432509
@ -25,7 +25,6 @@ import fr.xephi.authme.listener.AuthMePlayerListener;
|
|||||||
import fr.xephi.authme.listener.AuthMePlayerListener16;
|
import fr.xephi.authme.listener.AuthMePlayerListener16;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener18;
|
import fr.xephi.authme.listener.AuthMePlayerListener18;
|
||||||
import fr.xephi.authme.listener.AuthMeServerListener;
|
import fr.xephi.authme.listener.AuthMeServerListener;
|
||||||
import fr.xephi.authme.mail.SendMailSSL;
|
|
||||||
import fr.xephi.authme.output.ConsoleFilter;
|
import fr.xephi.authme.output.ConsoleFilter;
|
||||||
import fr.xephi.authme.output.Log4JFilter;
|
import fr.xephi.authme.output.Log4JFilter;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
@ -79,8 +78,6 @@ import java.util.List;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT;
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +111,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
private AuthMeServiceInitializer initializer;
|
private AuthMeServiceInitializer initializer;
|
||||||
private GeoLiteAPI geoLiteApi;
|
private GeoLiteAPI geoLiteApi;
|
||||||
private SendMailSSL mail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -248,9 +244,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// Set console filter
|
// Set console filter
|
||||||
setupConsoleFilter();
|
setupConsoleFilter();
|
||||||
|
|
||||||
// Set up the mail API
|
|
||||||
setupMailApi();
|
|
||||||
|
|
||||||
// Do a backup on start
|
// Do a backup on start
|
||||||
// TODO: maybe create a backup manager?
|
// TODO: maybe create a backup manager?
|
||||||
new PerformBackup(this, newSettings).doBackup(PerformBackup.BackupCause.START);
|
new PerformBackup(this, newSettings).doBackup(PerformBackup.BackupCause.START);
|
||||||
@ -303,16 +296,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
initializer.get(API.class);
|
initializer.get(API.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the mail API, if enabled.
|
|
||||||
*/
|
|
||||||
private void setupMailApi() {
|
|
||||||
// Make sure the mail API is enabled
|
|
||||||
if (!newSettings.getProperty(MAIL_ACCOUNT).isEmpty() && !newSettings.getProperty(MAIL_PASSWORD).isEmpty()) {
|
|
||||||
this.mail = new SendMailSSL(this, newSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the settings warnings, for various risky settings.
|
* Show the settings warnings, for various risky settings.
|
||||||
*/
|
*/
|
||||||
@ -673,15 +656,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
return commandHandler.processCommand(sender, commandLabel, args);
|
return commandHandler.processCommand(sender, commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the mailing instance.
|
|
||||||
*
|
|
||||||
* @return The send mail instance.
|
|
||||||
*/
|
|
||||||
public SendMailSSL getMail() {
|
|
||||||
return this.mail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------
|
// -------------
|
||||||
// Service getters (deprecated)
|
// Service getters (deprecated)
|
||||||
// Use @Inject fields instead
|
// Use @Inject fields instead
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
|
|||||||
|
|
||||||
if (dataSource.updatePassword(auth)) {
|
if (dataSource.updatePassword(auth)) {
|
||||||
commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||||
ConsoleLogger.info(playerNameLowerCase + "'s password changed");
|
ConsoleLogger.info(sender.getName() + " changed password of " + playerNameLowerCase);
|
||||||
} else {
|
} else {
|
||||||
commandService.send(sender, MessageKey.ERROR);
|
commandService.send(sender, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
package fr.xephi.authme.command.executable.email;
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.command.PlayerCommand;
|
import fr.xephi.authme.command.PlayerCommand;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.mail.SendMailSSL;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
@ -33,15 +33,14 @@ public class RecoverEmailCommand extends PlayerCommand {
|
|||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
// TODO #655: Remove injected AuthMe instance once Authme#mail is encapsulated
|
private SendMailSSL sendMailSsl;
|
||||||
private AuthMe plugin;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(Player player, List<String> arguments) {
|
public void runCommand(Player player, List<String> arguments) {
|
||||||
final String playerMail = arguments.get(0);
|
final String playerMail = arguments.get(0);
|
||||||
final String playerName = player.getName();
|
final String playerName = player.getName();
|
||||||
|
|
||||||
if (plugin.getMail() == null) {
|
if (!sendMailSsl.hasAllInformation()) {
|
||||||
ConsoleLogger.showError("Mail API is not set");
|
ConsoleLogger.showError("Mail API is not set");
|
||||||
commandService.send(player, MessageKey.ERROR);
|
commandService.send(player, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
@ -76,7 +75,7 @@ public class RecoverEmailCommand extends PlayerCommand {
|
|||||||
}
|
}
|
||||||
auth.setPassword(hashNew);
|
auth.setPassword(hashNew);
|
||||||
dataSource.updatePassword(auth);
|
dataSource.updatePassword(auth);
|
||||||
plugin.getMail().main(auth, thePass);
|
sendMailSsl.sendPasswordMail(auth, thePass);
|
||||||
commandService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
commandService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
commandService.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
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.ConsoleLogger;
|
||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.command.PlayerCommand;
|
import fr.xephi.authme.command.PlayerCommand;
|
||||||
|
import fr.xephi.authme.mail.SendMailSSL;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
@ -27,6 +28,9 @@ public class RegisterCommand extends PlayerCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private CommandService commandService;
|
private CommandService commandService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SendMailSSL sendMailSsl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(Player player, List<String> arguments) {
|
public void runCommand(Player player, List<String> arguments) {
|
||||||
if (commandService.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) {
|
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) {
|
private void handleEmailRegistration(Player player, List<String> arguments) {
|
||||||
if (commandService.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) {
|
if (!sendMailSsl.hasAllInformation()) {
|
||||||
player.sendMessage("Cannot register: no email address is set for the server. "
|
player.sendMessage("Cannot register: not all required settings are set for sending emails. "
|
||||||
+ "Please contact an administrator");
|
+ "Please contact an administrator");
|
||||||
ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email is set "
|
ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email or password is set "
|
||||||
+ "to send emails from. Please add one in your config at " + EmailSettings.MAIL_ACCOUNT.getPath());
|
+ "to send emails from. Please adjust your config at " + EmailSettings.MAIL_ACCOUNT.getPath());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,12 +54,10 @@ public class MySQL implements DataSource {
|
|||||||
if (e instanceof IllegalArgumentException) {
|
if (e instanceof IllegalArgumentException) {
|
||||||
ConsoleLogger.showError("Invalid database arguments! Please check your configuration!");
|
ConsoleLogger.showError("Invalid database arguments! Please check your configuration!");
|
||||||
ConsoleLogger.showError("If this error persists, please report it to the developer!");
|
ConsoleLogger.showError("If this error persists, please report it to the developer!");
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
if (e instanceof PoolInitializationException) {
|
if (e instanceof PoolInitializationException) {
|
||||||
ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!");
|
ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!");
|
||||||
ConsoleLogger.showError("If this error persists, please report it to the developer!");
|
ConsoleLogger.showError("If this error persists, please report it to the developer!");
|
||||||
throw new PoolInitializationException(e);
|
|
||||||
}
|
}
|
||||||
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer!");
|
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer!");
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@ -5,45 +5,72 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
|
import fr.xephi.authme.util.BukkitService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.apache.commons.mail.EmailConstants;
|
import org.apache.commons.mail.EmailConstants;
|
||||||
import org.apache.commons.mail.EmailException;
|
import org.apache.commons.mail.EmailException;
|
||||||
import org.apache.commons.mail.HtmlEmail;
|
import org.apache.commons.mail.HtmlEmail;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import javax.activation.DataSource;
|
import javax.activation.DataSource;
|
||||||
import javax.activation.FileDataSource;
|
import javax.activation.FileDataSource;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT;
|
||||||
|
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
*/
|
*/
|
||||||
public class SendMailSSL {
|
public class SendMailSSL {
|
||||||
|
|
||||||
private final AuthMe plugin;
|
@Inject
|
||||||
private final NewSetting settings;
|
private AuthMe plugin;
|
||||||
|
@Inject
|
||||||
|
private NewSetting settings;
|
||||||
|
@Inject
|
||||||
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
public SendMailSSL(AuthMe plugin, NewSetting settings) {
|
SendMailSSL() {
|
||||||
this.plugin = plugin;
|
|
||||||
this.settings = settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void main(final PlayerAuth auth, final String newPass) {
|
/**
|
||||||
final String mailText = replaceMailTags(settings.getEmailMessage(), plugin, auth, newPass);
|
* Returns whether all necessary settings are set for sending mails.
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
*
|
||||||
|
* @return true if the necessary email settings are set, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean hasAllInformation() {
|
||||||
|
return !settings.getProperty(MAIL_ACCOUNT).isEmpty()
|
||||||
|
&& !settings.getProperty(MAIL_PASSWORD).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an email to the user with his new password.
|
||||||
|
*
|
||||||
|
* @param auth the player auth of the player
|
||||||
|
* @param newPass the new password
|
||||||
|
*/
|
||||||
|
public void sendPasswordMail(final PlayerAuth auth, final String newPass) {
|
||||||
|
if (!hasAllInformation()) {
|
||||||
|
ConsoleLogger.showError("Cannot perform email registration: not all email settings are complete");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String mailText = replaceMailTags(settings.getEmailMessage(), auth, newPass);
|
||||||
|
bukkitService.runTaskAsynchronously(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||||
HtmlEmail email;
|
HtmlEmail email;
|
||||||
try {
|
try {
|
||||||
email = initializeMail(auth, settings);
|
email = initializeMail(auth.getEmail());
|
||||||
} catch (EmailException e) {
|
} catch (EmailException e) {
|
||||||
ConsoleLogger.logException("Failed to create email with the given settings:", e);
|
ConsoleLogger.logException("Failed to create email with the given settings:", e);
|
||||||
return;
|
return;
|
||||||
@ -54,7 +81,7 @@ public class SendMailSSL {
|
|||||||
File file = null;
|
File file = null;
|
||||||
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
|
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
|
||||||
try {
|
try {
|
||||||
file = generateImage(auth, plugin, newPass);
|
file = generateImage(auth.getNickname(), plugin, newPass);
|
||||||
content = embedImageIntoEmailContent(file, email, content);
|
content = embedImageIntoEmailContent(file, email, content);
|
||||||
} catch (IOException | EmailException e) {
|
} catch (IOException | EmailException e) {
|
||||||
ConsoleLogger.logException(
|
ConsoleLogger.logException(
|
||||||
@ -67,13 +94,12 @@ public class SendMailSSL {
|
|||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File generateImage(PlayerAuth auth, AuthMe plugin, String newPass) throws IOException {
|
private static File generateImage(String name, AuthMe plugin, String newPass) throws IOException {
|
||||||
ImageGenerator gen = new ImageGenerator(newPass);
|
ImageGenerator gen = new ImageGenerator(newPass);
|
||||||
File file = new File(plugin.getDataFolder(), auth.getNickname() + "_new_pass.jpg");
|
File file = new File(plugin.getDataFolder(), name + "_new_pass.jpg");
|
||||||
ImageIO.write(gen.generateImage(), "jpg", file);
|
ImageIO.write(gen.generateImage(), "jpg", file);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -85,8 +111,7 @@ public class SendMailSSL {
|
|||||||
return content.replace("<image />", "<img src=\"cid:" + tag + "\">");
|
return content.replace("<image />", "<img src=\"cid:" + tag + "\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HtmlEmail initializeMail(PlayerAuth auth, NewSetting settings)
|
private HtmlEmail initializeMail(String emailAddress) throws EmailException {
|
||||||
throws EmailException {
|
|
||||||
String senderMail = settings.getProperty(EmailSettings.MAIL_ACCOUNT);
|
String senderMail = settings.getProperty(EmailSettings.MAIL_ACCOUNT);
|
||||||
String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME))
|
String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME))
|
||||||
? senderMail
|
? senderMail
|
||||||
@ -98,12 +123,12 @@ public class SendMailSSL {
|
|||||||
email.setCharset(EmailConstants.UTF_8);
|
email.setCharset(EmailConstants.UTF_8);
|
||||||
email.setSmtpPort(port);
|
email.setSmtpPort(port);
|
||||||
email.setHostName(settings.getProperty(EmailSettings.SMTP_HOST));
|
email.setHostName(settings.getProperty(EmailSettings.SMTP_HOST));
|
||||||
email.addTo(auth.getEmail());
|
email.addTo(emailAddress);
|
||||||
email.setFrom(senderMail, senderName);
|
email.setFrom(senderMail, senderName);
|
||||||
email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
|
email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
|
||||||
email.setAuthentication(senderMail, mailPassword);
|
email.setAuthentication(senderMail, mailPassword);
|
||||||
|
|
||||||
setPropertiesForPort(email, port, settings);
|
setPropertiesForPort(email, port);
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,15 +149,14 @@ public class SendMailSSL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String replaceMailTags(String mailText, AuthMe plugin, PlayerAuth auth, String newPass) {
|
private String replaceMailTags(String mailText, PlayerAuth auth, String newPass) {
|
||||||
return mailText
|
return mailText
|
||||||
.replace("<playername />", auth.getNickname())
|
.replace("<playername />", auth.getNickname())
|
||||||
.replace("<servername />", plugin.getServer().getServerName())
|
.replace("<servername />", plugin.getServer().getServerName())
|
||||||
.replace("<generatedpass />", newPass);
|
.replace("<generatedpass />", newPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setPropertiesForPort(HtmlEmail email, int port, NewSetting settings)
|
private void setPropertiesForPort(HtmlEmail email, int port) throws EmailException {
|
||||||
throws EmailException {
|
|
||||||
switch (port) {
|
switch (port) {
|
||||||
case 587:
|
case 587:
|
||||||
String oAuth2Token = settings.getProperty(EmailSettings.OAUTH2_TOKEN);
|
String oAuth2Token = settings.getProperty(EmailSettings.OAUTH2_TOKEN);
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
|
|||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.mail.SendMailSSL;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
@ -55,6 +56,9 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SendMailSSL sendMailSsl;
|
||||||
|
|
||||||
AsyncRegister() { }
|
AsyncRegister() { }
|
||||||
|
|
||||||
private boolean preRegisterCheck(Player player, String password) {
|
private boolean preRegisterCheck(Player player, String password) {
|
||||||
@ -137,7 +141,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
database.updateEmail(auth);
|
database.updateEmail(auth);
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
plugin.getMail().main(auth, password);
|
sendMailSsl.sendPasswordMail(auth, password);
|
||||||
syncProcessManager.processSyncEmailRegister(player);
|
syncProcessManager.processSyncEmailRegister(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package fr.xephi.authme.command.executable.register;
|
|||||||
|
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
|
import fr.xephi.authme.mail.SendMailSSL;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
@ -49,6 +50,8 @@ public class RegisterCommandTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Management management;
|
private Management management;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SendMailSSL sendMailSsl;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
@ -72,7 +75,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(sender).sendMessage(argThat(containsString("Player only!")));
|
verify(sender).sendMessage(argThat(containsString("Player only!")));
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management, sendMailSsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -86,6 +89,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(management).performRegister(player, "", "", true);
|
verify(management).performRegister(player, "", "", true);
|
||||||
|
verifyZeroInteractions(sendMailSsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -98,7 +102,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management, sendMailSsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -112,7 +116,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management, sendMailSsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -127,7 +131,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management, sendMailSsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -135,14 +139,15 @@ public class RegisterCommandTest {
|
|||||||
// given
|
// given
|
||||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(false);
|
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(false);
|
||||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("");
|
given(sendMailSsl.hasAllInformation()).willReturn(false);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(player, Collections.singletonList("myMail@example.tld"));
|
command.executeCommand(player, Collections.singletonList("myMail@example.tld"));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(player).sendMessage(argThat(containsString("no email address")));
|
verify(player).sendMessage(argThat(containsString("not all required settings are set for sending emails")));
|
||||||
|
verify(sendMailSsl).hasAllInformation();
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +160,7 @@ public class RegisterCommandTest {
|
|||||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||||
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -175,6 +181,7 @@ public class RegisterCommandTest {
|
|||||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||||
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -182,6 +189,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||||
|
verify(sendMailSsl).hasAllInformation();
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +204,7 @@ public class RegisterCommandTest {
|
|||||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||||
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -203,6 +212,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).validateEmail(playerMail);
|
verify(commandService).validateEmail(playerMail);
|
||||||
|
verify(sendMailSsl).hasAllInformation();
|
||||||
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +227,7 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commandService).send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
verify(commandService).send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||||
verifyZeroInteractions(management);
|
verifyZeroInteractions(management, sendMailSsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -120,11 +120,6 @@ public class SQLiteIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||||||
assertThat(sqLite.getAllAuths(), hasSize(1));
|
assertThat(sqLite.getAllAuths(), hasSize(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldCreate2() throws SQLException {
|
|
||||||
con.createStatement().execute("SELECT 1 from authme");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataSource getDataSource(String saltColumn) {
|
protected DataSource getDataSource(String saltColumn) {
|
||||||
when(settings.getProperty(DatabaseSettings.MYSQL_COL_SALT)).thenReturn(saltColumn);
|
when(settings.getProperty(DatabaseSettings.MYSQL_COL_SALT)).thenReturn(saltColumn);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user