mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
trabajando en el signup. problema con el mismo username aunque este delete at
This commit is contained in:
@ -27,28 +27,49 @@ public class EmailService {
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public void sendPasswordResetMail(String to, String username, String resetLink, Locale locale) throws MessagingException {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
public void sendPasswordResetMail(String to, String fullName, String resetUrl, Locale locale) {
|
||||
String subject = messageSource.getMessage("email.resetPassword.title", null, locale);
|
||||
Map<String, Object> variables = Map.of(
|
||||
"fullName", fullName,
|
||||
"resetUrl", resetUrl);
|
||||
sendEmail(to, subject, "imprimelibros/email/reset-password", variables);
|
||||
}
|
||||
|
||||
helper.setFrom("no-reply@imprimelibros.com");
|
||||
helper.setTo(to);
|
||||
helper.setSubject(messageSource.getMessage("email.resetPassword.title", null, locale));
|
||||
public void sendVerificationEmail(String to, String fullName, String verifyUrl, Locale locale) {
|
||||
String subject = messageSource.getMessage("email.verify.title", null, locale);
|
||||
Map<String, Object> variables = Map.of(
|
||||
"fullName", fullName,
|
||||
"verifyUrl", verifyUrl);
|
||||
sendEmail(to, subject, "imprimelibros/email/verify", variables);
|
||||
}
|
||||
|
||||
// Variables para la plantilla
|
||||
Context context = new Context();
|
||||
context.setVariables(Map.of(
|
||||
"username", username,
|
||||
"resetLink", resetLink,
|
||||
"year", String.valueOf(java.time.Year.now().getValue())
|
||||
));
|
||||
|
||||
// Procesar plantilla HTML
|
||||
String html = templateEngine.process("email/password-reset", context);
|
||||
helper.setText(html, true);
|
||||
// ->>>>>>>> PRIVATE METHODS <<<<<<<<<<<-
|
||||
|
||||
helper.addInline("companyLogo", new ClassPathResource("static/images/logo-light.png"));
|
||||
/******************
|
||||
* Envía un email usando una plantilla Thymeleaf.
|
||||
* @param to
|
||||
* @param subject
|
||||
* @param template
|
||||
* @param variables
|
||||
**********************************************/
|
||||
|
||||
mailSender.send(message);
|
||||
private void sendEmail(String to, String subject, String template, Map<String, Object> variables) {
|
||||
try {
|
||||
Context context = new Context();
|
||||
context.setVariables(variables);
|
||||
String html = templateEngine.process(template, context);
|
||||
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
helper.setFrom("no-reply@imprimelibros.com");
|
||||
helper.setTo(to);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(html, true);
|
||||
|
||||
mailSender.send(message);
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user