Skip to content

Commit d5c63ea

Browse files
committed
feature: Added emailTemplate in common-settings.
1 parent 96081d3 commit d5c63ea

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/organization/service/OrganizationServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.lowcoder.domain.organization.service;
22

33
import static org.lowcoder.domain.authentication.AuthenticationService.DEFAULT_AUTH_CONFIG;
4+
import static org.lowcoder.domain.organization.model.Organization.OrganizationCommonSettings.PASSWORD_RESET_EMAIL_TEMPLATE;
45
import static org.lowcoder.domain.organization.model.OrganizationState.ACTIVE;
56
import static org.lowcoder.domain.organization.model.OrganizationState.DELETED;
67
import static org.lowcoder.domain.util.QueryDslUtils.fieldName;
@@ -56,6 +57,12 @@ public class OrganizationServiceImpl implements OrganizationService {
5657

5758
private final Conf<Integer> logoMaxSizeInKb;
5859

60+
private static final String PASSWORD_RESET_EMAIL_TEMPLATE_DEFAULT = "<p>Hi, %s<br/>" +
61+
"Here is the link to reset your password: %s<br/>" +
62+
"Please note that the link will expire after 12 hours.<br/><br/>" +
63+
"Regards,<br/>" +
64+
"The Lowcoder Team</p>";
65+
5966
@Autowired
6067
private AssetRepository assetRepository;
6168

@@ -151,6 +158,8 @@ public Mono<Organization> create(Organization organization, String creatorId) {
151158
if (organization == null || StringUtils.isNotBlank(organization.getId())) {
152159
return Mono.error(new BizException(BizError.INVALID_PARAMETER, "INVALID_PARAMETER", FieldName.ORGANIZATION));
153160
}
161+
organization.getCommonSettings().put(PASSWORD_RESET_EMAIL_TEMPLATE,
162+
PASSWORD_RESET_EMAIL_TEMPLATE_DEFAULT);
154163
organization.setState(ACTIVE);
155164
return Mono.just(organization);
156165
})

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/service/EmailCommunicationService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public class EmailCommunicationService {
1818
@Value("${spring.mail.username}")
1919
private String fromEmail;
2020

21-
public boolean sendMail(String to, String token, String message) {
21+
@Value("${common.lowcoder_public_url}")
22+
private String lowcoderPublicUrl;
23+
24+
public boolean sendPasswordResetEmail(String to, String token, String message) {
2225
try {
2326
String subject = "Reset Your Password";
2427
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
@@ -31,8 +34,8 @@ public boolean sendMail(String to, String token, String message) {
3134

3235
// Construct the message with the token link
3336
String resetLink = lowcoderPublicUrl + "/api/users/lost-password/" + token;
34-
String messageWithLink = message + "\n\nReset your password here: " + resetLink;
35-
mimeMessageHelper.setText(messageWithLink, true); // Set HTML to true to allow links
37+
String formattedMessage = String.format(message, to, resetLink);
38+
mimeMessageHelper.setText(formattedMessage, true); // Set HTML to true to allow links
3639

3740
javaMailSender.send(mimeMessage);
3841

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/service/UserServiceImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242

4343
import javax.annotation.Nonnull;
4444
import java.security.SecureRandom;
45-
import java.time.Duration;
4645
import java.time.Instant;
47-
import java.time.LocalDate;
4846
import java.time.temporal.ChronoUnit;
4947
import java.util.*;
5048
import java.util.function.Function;
@@ -283,8 +281,7 @@ public Mono<Boolean> lostPassword(String userEmail) {
283281

284282
String token = generateNewRandomPwd();
285283
Instant tokenExpiry = Instant.now().plus(12, ChronoUnit.HOURS);
286-
287-
if (!emailCommunicationService.sendMail(userEmail, token, emailTemplate)) {
284+
if (!emailCommunicationService.sendPasswordResetEmail(userEmail, token, emailTemplate)) {
288285
return ofError(BizError.AUTH_ERROR, "SENDING_EMAIL_FAILED");
289286
}
290287
user.setPasswordResetToken(HashUtils.hash(token.getBytes()));

0 commit comments

Comments
 (0)