mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 17:47:38 +01:00
Option to send an image as new password
This commit is contained in:
parent
30b3dff965
commit
f114019e5f
33
src/main/java/fr/xephi/authme/ImageGenerator.java
Normal file
33
src/main/java/fr/xephi/authme/ImageGenerator.java
Normal file
@ -0,0 +1,33 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ImageGenerator {
|
||||
|
||||
private String pass;
|
||||
private AuthMe plugin;
|
||||
|
||||
public ImageGenerator(AuthMe plugin, String pass) {
|
||||
this.pass = pass;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public BufferedImage generateImage() {
|
||||
BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.fillRect(0, 0, 200, 40);
|
||||
GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true);
|
||||
graphics.setPaint(gradientPaint);
|
||||
Font font = new Font("Comic Sans MS", Font.BOLD, 30);
|
||||
graphics.setFont(font);
|
||||
graphics.drawString(pass, 5, 30);
|
||||
graphics.dispose();
|
||||
image.flush();
|
||||
return image;
|
||||
}
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.Multipart;
|
||||
@ -73,10 +78,26 @@ public class SendMailSSL {
|
||||
messageBodyPart.setText(mailText);
|
||||
Multipart multipart = new MimeMultipart();
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
|
||||
// Generate an image ?
|
||||
File file = null;
|
||||
if (Settings.generateImage) {
|
||||
ImageGenerator gen = new ImageGenerator(plugin, newPass);
|
||||
file = new File(plugin.getDataFolder() + File.separator + auth.getNickname() + "_new_pass.jpg");
|
||||
ImageIO.write(gen.generateImage(), "jpg", file);
|
||||
messageBodyPart = new MimeBodyPart();
|
||||
DataSource source = new FileDataSource(file);
|
||||
messageBodyPart.setDataHandler(new DataHandler(source));
|
||||
messageBodyPart.setFileName(auth.getNickname() + "_new_pass.jpg");
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
}
|
||||
|
||||
message.setContent(multipart);
|
||||
Transport transport = session.getTransport("smtp");
|
||||
transport.connect(smtp, acc, password);
|
||||
transport.sendMessage(message, message.getAllRecipients());
|
||||
if (file != null)
|
||||
file.delete();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Some error occured while trying to send a mail to " + mail);
|
||||
|
@ -70,7 +70,7 @@ public final class Settings extends YamlConfiguration {
|
||||
purgePermissions, enableProtection, enableAntiBot, recallEmail,
|
||||
useWelcomeMessage, broadcastWelcomeMessage, forceRegKick,
|
||||
forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport,
|
||||
applyBlindEffect, customAttributes;
|
||||
applyBlindEffect, customAttributes, generateImage;
|
||||
|
||||
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
|
||||
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
|
||||
@ -269,6 +269,7 @@ public final class Settings extends YamlConfiguration {
|
||||
forceRegisterCommands = (List<String>) configFile.getList("settings.forceRegisterCommands", new ArrayList<String>());
|
||||
forceRegisterCommandsAsConsole = (List<String>) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
|
||||
customAttributes = configFile.getBoolean("Hooks.customAttributes");
|
||||
generateImage = configFile.getBoolean("Email.generateImage", true);
|
||||
|
||||
// Load the welcome message
|
||||
getWelcomeMessage(plugin);
|
||||
@ -435,6 +436,7 @@ public final class Settings extends YamlConfiguration {
|
||||
forceRegisterCommands = (List<String>) configFile.getList("settings.forceRegisterCommands", new ArrayList<String>());
|
||||
forceRegisterCommandsAsConsole = (List<String>) configFile.getList("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
|
||||
customAttributes = configFile.getBoolean("Hooks.customAttributes");
|
||||
generateImage = configFile.getBoolean("Email.generateImage", true);
|
||||
|
||||
// Reload the welcome message
|
||||
getWelcomeMessage(AuthMe.getInstance());
|
||||
@ -587,6 +589,10 @@ public final class Settings extends YamlConfiguration {
|
||||
}
|
||||
if (contains("Hooks.notifications"))
|
||||
set("Hooks.notifications", null);
|
||||
if (!contains("Email.generateImage")) {
|
||||
set("Email.generateImage", true);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
if (changes) {
|
||||
plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me");
|
||||
|
Loading…
Reference in New Issue
Block a user