Skip to content

Commit

Permalink
replaced custom email-template-builder by separated project
Browse files Browse the repository at this point in the history
  • Loading branch information
melistik committed Jun 25, 2018
1 parent 6e51adf commit 24227e6
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 450 deletions.
5 changes: 5 additions & 0 deletions commons-auth-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ SOFTWARE.
<artifactId>commons-rest-server</artifactId>
<version>${commons-rest.version}</version>
</dependency>
<dependency>
<groupId>io.rocketbase.commons</groupId>
<artifactId>email-template-builder</artifactId>
<version>${email-template-builder.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.rocketbase.commons.service.email;

import io.rocketbase.commons.email.model.HtmlTextEmail;
import io.rocketbase.commons.model.AppUser;
import io.rocketbase.commons.service.email.EmailTemplateService.HtmlTextEmail;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -25,21 +25,16 @@ public class EmailService {
@Resource
private MailContentConfig mailContentConfig;

@Resource
private EmailTemplateService emailTemplateService;

@SneakyThrows
public void sentRegistrationEmail(AppUser user, String verificationUrl) {
TemplateConfigBuilder register = mailContentConfig.register(user, verificationUrl);
HtmlTextEmail htmlTextEmail = emailTemplateService.buildHtmlTextTemplate(register);
HtmlTextEmail htmlTextEmail = mailContentConfig.register(user, verificationUrl);

sentEmail(new InternetAddress(user.getEmail()), mailContentConfig.registerSubject(user), htmlTextEmail);
}

@SneakyThrows
public void sentForgotPasswordEmail(AppUser user, String verificationUrl) {
TemplateConfigBuilder forgotPassword = mailContentConfig.forgotPassword(user, verificationUrl);
HtmlTextEmail htmlTextEmail = emailTemplateService.buildHtmlTextTemplate(forgotPassword);
HtmlTextEmail htmlTextEmail = mailContentConfig.forgotPassword(user, verificationUrl);

sentEmail(new InternetAddress(user.getEmail()), mailContentConfig.forgotPasswordSubject(user), htmlTextEmail);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.rocketbase.commons.service.email;

import io.rocketbase.commons.email.model.HtmlTextEmail;
import io.rocketbase.commons.model.AppUser;

public interface MailContentConfig {

TemplateConfigBuilder register(AppUser user, String actionUrl);
HtmlTextEmail register(AppUser user, String actionUrl);

String registerSubject(AppUser user);

TemplateConfigBuilder forgotPassword(AppUser user, String actionUrl);
HtmlTextEmail forgotPassword(AppUser user, String actionUrl);

String forgotPasswordSubject(AppUser user);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.rocketbase.commons.service.email;

import io.rocketbase.commons.config.EmailProperties;
import io.rocketbase.commons.email.EmailTemplateBuilder;
import io.rocketbase.commons.email.model.HtmlTextEmail;
import io.rocketbase.commons.email.template.ColorStyle;
import io.rocketbase.commons.model.AppUser;
import lombok.RequiredArgsConstructor;

Expand All @@ -10,16 +13,17 @@ public class SimpleMailContentConfig implements MailContentConfig {
final EmailProperties emailProperties;

@Override
public TemplateConfigBuilder register(AppUser user, String actionUrl) {
return TemplateConfigBuilder.build()
.title("Please Verify Your Account")
public HtmlTextEmail register(AppUser user, String actionUrl) {
return EmailTemplateBuilder.builder()
.header("Verify Your Account")
.addLine(String.format("Hi %s,", user.getUsername()))
.addLine("please verify your account by clicking the button")
.action(actionUrl, "verify your account")
.addGreeting(String.format("- %s", emailProperties.getServiceName()))
.receiveNote(emailProperties.getServiceName(), emailProperties.getSupportEmail())
.copyright(emailProperties.getCopyrightUrl(), emailProperties.getCopyrightName());
.addText(String.format("Hi %s,", user.getUsername()))
.addText("please verify your account by clicking the button")
.addButton("verify your account", actionUrl)
.addText(String.format("- %s", emailProperties.getServiceName()))
.addFooter(String.format("You’re receiving this email because you have an account in %s.<br>" +
"If you are not sure why you’re receiving this, please contact us %s", emailProperties.getServiceName(), emailProperties.getSupportEmail()), true)
.copyright(emailProperties.getCopyrightUrl(), emailProperties.getCopyrightName())
.build();
}

@Override
Expand All @@ -28,16 +32,17 @@ public String registerSubject(AppUser user) {
}

@Override
public TemplateConfigBuilder forgotPassword(AppUser user, String actionUrl) {
return TemplateConfigBuilder.build()
.title("Reset Password")
.headerWithStyling("You have submitted a password change request!", "fff", "E63946")
.addLine(String.format("Hi %s,", user.getUsername()))
.addLine("if it was you, confirm the password change by clicking the button")
.actionWithStyling(actionUrl, "confirm password change", "fff", "E63946")
.addGreeting(String.format("- %s", emailProperties.getServiceName()))
.receiveNote(emailProperties.getServiceName(), emailProperties.getSupportEmail())
.copyright(emailProperties.getCopyrightUrl(), emailProperties.getCopyrightName());
public HtmlTextEmail forgotPassword(AppUser user, String actionUrl) {
return EmailTemplateBuilder.builder()
.header("You have submitted a password change request!", new ColorStyle("fff", "E63946"))
.addText(String.format("Hi %s,", user.getUsername()))
.addText("if it was you, confirm the password change by clicking the button")
.addButton("confirm password change", actionUrl, new ColorStyle("fff", "E63946"))
.addText(String.format("- %s", emailProperties.getServiceName()))
.addFooter(String.format("You’re receiving this email because you have an account in %s.<br>" +
"If you are not sure why you’re receiving this, please contact us %s", emailProperties.getServiceName(), emailProperties.getSupportEmail()), true)
.copyright(emailProperties.getCopyrightUrl(), emailProperties.getCopyrightName())
.build();
}

@Override
Expand Down

This file was deleted.

Loading

0 comments on commit 24227e6

Please sign in to comment.