Skip to content

Invite by email #1640

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 5 commits into from
Apr 19, 2025
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
endpoint for invitation email
  • Loading branch information
dragonpoo committed Apr 16, 2025
commit a81143198b1a022726968bfd1353edeedf47859c
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface EmailCommunicationService {
boolean sendPasswordResetEmail(String to, String token, String message);
boolean sendInviteEmail(String[] to, String token, String message);
boolean sendInvitationEmails(String[] to, String inviteLink, String message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean sendPasswordResetEmail(String to, String token, String message) {
}

@Override
public boolean sendInviteEmail(String[] to, String inviteLink, String message) {
public boolean sendInvitationEmails(String[] to, String inviteLink, String message) {
try {
String subject = "You've been invited!";
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
Expand All @@ -62,7 +62,7 @@ public boolean sendInviteEmail(String[] to, String inviteLink, String message) {
mimeMessageHelper.setSubject(subject);

// Construct the message with the invite link
String formattedMessage = String.format(message, String.join(", ", to), inviteLink);
String formattedMessage = String.format(message, inviteLink);
mimeMessageHelper.setText(formattedMessage, true); // Set HTML to true to allow links

javaMailSender.send(mimeMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.lowcoder.api.authentication;

import lombok.RequiredArgsConstructor;
import java.util.List;

import org.lowcoder.api.authentication.dto.APIKeyRequest;
import org.lowcoder.api.authentication.dto.AuthConfigRequest;
import org.lowcoder.api.authentication.service.AuthenticationApiService;
Expand All @@ -12,6 +13,7 @@
import org.lowcoder.api.util.BusinessEventPublisher;
import org.lowcoder.domain.authentication.FindAuthConfig;
import org.lowcoder.domain.user.model.APIKey;
import org.lowcoder.domain.user.service.EmailCommunicationService;
import org.lowcoder.domain.user.service.UserService;
import org.lowcoder.sdk.auth.AbstractAuthConfig;
import org.lowcoder.sdk.util.CookieHelper;
Expand All @@ -20,9 +22,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Mono;

@RequiredArgsConstructor
@RestController
Expand All @@ -34,6 +36,7 @@ public class AuthenticationController implements AuthenticationEndpoints
private final CookieHelper cookieHelper;
private final BusinessEventPublisher businessEventPublisher;
private final UserService userService;
private final EmailCommunicationService emailCommunicationService;

/**
* login by email or phone with password; or register by email for now.
Expand Down Expand Up @@ -134,4 +137,13 @@ public Mono<ResponseView<?>> bindEmail(@RequestParam String email) {
return sessionUserService.getVisitor().flatMap(user -> userService.bindEmail(user, email))
.map(ResponseView::success);
}

@Override
public Mono<ResponseView<Boolean>> sendInvitationEmails(InviteEmailRequest req) {
boolean isSuccess = emailCommunicationService.sendInvitationEmails(req.emails(),
req.inviteLink(),
"You have been invited to join our platform. Click here to accept the invitation: %s");

return Mono.just(ResponseView.success(isSuccess));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ public Mono<ResponseView<Boolean>> linkAccountWithThirdParty(
)
@PostMapping("/email/bind")
public Mono<ResponseView<?>> bindEmail(@RequestParam String email);

@Operation(
tags = TAG_AUTHENTICATION,
operationId = "sendInvitationEmails",
summary = "Send invitation emails",
description = "Send invitation emails to the specified addresses"
)
@PostMapping("/email/invite")
public Mono<ResponseView<Boolean>> sendInvitationEmails(@RequestBody InviteEmailRequest req);

/**
* @param loginId phone number or email for now.
Expand All @@ -159,4 +168,11 @@ public Mono<ResponseView<Boolean>> linkAccountWithThirdParty(
*/
public record FormLoginRequest(String loginId, String password, boolean register, String source, String authId) {
}
}
/**
* @param emails email addresses to send the invitation to
* @param inviteLink the link to be included in the email
*/
public record InviteEmailRequest(String[] emails, String inviteLink) {
}
}