Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't use self reference #24431

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import jakarta.mail.internet.MimeMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Lazy;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
Expand Down Expand Up @@ -62,10 +60,6 @@ public class MailService {

private final SpringTemplateEngine templateEngine;

@Autowired
@Lazy
private MailService self;

public MailService(JHipsterProperties jHipsterProperties, JavaMailSender javaMailSender,
MessageSource messageSource, SpringTemplateEngine templateEngine) {

Expand All @@ -77,6 +71,10 @@ public class MailService {

@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
this.internalSendEmail(to, subject, content, isMultipart, isHtml);
}

private void internalSendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);

Expand All @@ -97,6 +95,10 @@ public class MailService {

@Async
public void sendEmailFromTemplate(<%= user.persistClass %> user, String templateName, String titleKey) {
this.internalSendEmailFromTemplate(user, templateName, titleKey);
}

private void internalSendEmailFromTemplate(<%= user.persistClass %> user, String templateName, String titleKey) {
if (user.getEmail() == null) {
log.debug("Email doesn't exist for user '{}'", user.getLogin());
return;
Expand All @@ -107,26 +109,26 @@ public class MailService {
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process(templateName, context);
String subject = messageSource.getMessage(titleKey, null, locale);
self.sendEmail(user.getEmail(), subject, content, false, true);
this.internalSendEmail(user.getEmail(), subject, content, false, true);
}
<%_ if (!authenticationTypeOauth2) { _%>

@Async
public void sendActivationEmail(<%= user.persistClass %> user) {
log.debug("Sending activation email to '{}'", user.getEmail());
self.sendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title");
this.internalSendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title");
}

@Async
public void sendCreationEmail(<%= user.persistClass %> user) {
log.debug("Sending creation email to '{}'", user.getEmail());
self.sendEmailFromTemplate(user, "mail/creationEmail", "email.activation.title");
this.internalSendEmailFromTemplate(user, "mail/creationEmail", "email.activation.title");
}

@Async
public void sendPasswordResetMail(<%= user.persistClass %> user) {
log.debug("Sending password reset email to '{}'", user.getEmail());
self.sendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title");
this.internalSendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title");
}
<%_ } _%>
}
Loading