Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lost Password Feature #715

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

Merged
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Misc fixes
  • Loading branch information
aq-ikhwa-tech committed Feb 25, 2024
commit 65d9e2a0af759cca84bceef35cf0cdf8b6925f1c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import jakarta.mail.internet.MimeMessage;
import lombok.extern.slf4j.Slf4j;
import org.lowcoder.sdk.config.CommonConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
Expand All @@ -15,25 +15,22 @@ public class EmailCommunicationService {
@Autowired
private JavaMailSender javaMailSender;

@Value("${spring.mail.username}")
private String fromEmail;

@Value("${common.lowcoder_public_url}")
private String lowcoderPublicUrl;
@Autowired
private CommonConfig config;

public boolean sendPasswordResetEmail(String to, String token, String message) {
try {
String subject = "Reset Your Password";
String subject = "Reset Your Lost Password";
MimeMessage mimeMessage = javaMailSender.createMimeMessage();

MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);

mimeMessageHelper.setFrom(fromEmail);
mimeMessageHelper.setFrom(config.getLostPasswordEmailSender());
mimeMessageHelper.setTo(to);
mimeMessageHelper.setSubject(subject);

// Construct the message with the token link
String resetLink = lowcoderPublicUrl + "/api/users/lost-password/" + token;
String resetLink = config.getLowcoderPublicUrl() + "lost-password?token=" + token;
String formattedMessage = String.format(message, to, resetLink);
mimeMessageHelper.setText(formattedMessage, true); // Set HTML to true to allow links

Expand All @@ -42,7 +39,7 @@ public boolean sendPasswordResetEmail(String to, String token, String message) {
return true;

} catch (Exception e) {
log.error("Failed to send mail to: {}, Exception: {}", to, e);
log.error("Failed to send mail to: {}, Exception: ", to, e);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class CommonConfig {
private JsExecutor jsExecutor = new JsExecutor();
private Set<String> disallowedHosts = new HashSet<>();
private Marketplace marketplace = new Marketplace();
private SMTP smtp = new SMTP();
private String lowcoderPublicUrl;
private String lostPasswordEmailSender;

public boolean isSelfHost() {
return !isCloud();
Expand Down Expand Up @@ -147,13 +148,6 @@ public static class JsExecutor {
private String host;
}

@Data
public static class SMTP {
private String email;
private String host;
private String port;
}

@Data
public static class Marketplace {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {

ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/currentUser"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, USER_URL + "/lost-password"),

ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, GROUP_URL + "/list"), // application view
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, QUERY_URL + "/execute"), // application view
Expand All @@ -139,6 +140,7 @@ SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.APPLICATION_URL + "/marketplace-apps"), // marketplace apps
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.USER_URL + "/currentUser"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.USER_URL + "/lost-password"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.GROUP_URL + "/list"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, NewUrl.QUERY_URL + "/execute"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.MATERIAL_URL + "/**"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Mono<ResponseView<String>> resetPassword(@RequestBody ResetPasswordReques
@Override
public Mono<ResponseView<Boolean>> lostPassword(@RequestBody LostPasswordRequest request) {
if (StringUtils.isBlank(request.userEmail())) {
return ofError(BizError.INVALID_PARAMETER, "INVALID_USER_EMAIL");
return ofError(BizError.INVALID_PARAMETER, "INVALID_PARAMETER");
}
return userApiService.lostPassword(request.userEmail())
.map(ResponseView::success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ spring:
allow-bean-definition-overriding: true
allow-circular-references: true
mail:
# TODO - IRFAN this is just a test email to check the email sending.
username: "[email protected]"
password: "abcd"
host: "smtp.freesmtpservers.com"
host: smtp.freesmtpservers.com
port: 25
# properties:
# mail:
# smtp:
# starttls:
# enable: true
# auth: true

server:
compression:
Expand Down Expand Up @@ -58,7 +49,8 @@ common:
host: http://127.0.0.1:6060
marketplace:
private-mode: false
lowcoder_public_url: http://localhost:8080
lowcoder-public-url: http://localhost:8080
lost-password-email-sender: [email protected]

material:
mongodb-grid-fs:
Expand Down