Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit dbeddeb

Browse files
author
Sachin Maheshwari
committed
welcome email event
1 parent a08e423 commit dbeddeb

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

buildtokenproperties.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ AUTH0_NEW_DOMAIN=$(eval "echo \$${ENV}_AUTH0_NEW_DOMAIN")
4444
AUTH0_DOMAIN=$(eval "echo \$${ENV}_AUTH0_DOMAIN")
4545

4646
SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID")
47-
47+
SENDGRID_WELCOME_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_WELCOME_EMAIL_TEMPLATE_ID")
4848

4949

5050
if [[ -z "$ENV" ]] ; then
@@ -110,3 +110,4 @@ perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_DELETE\}\}|$M2MAUTHCONFIG_USERPROF
110110
perl -pi -e "s/\{\{AUTH0_NEW_DOMAIN\}\}/$AUTH0_NEW_DOMAIN/g" $CONFFILENAME
111111
perl -pi -e "s/\{\{AUTH0_DOMAIN\}\}/$AUTH0_DOMAIN/g" $CONFFILENAME
112112
perl -pi -e "s/\{\{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
113+
perl -pi -e "s/\{\{SENDGRID_WELCOME_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_WELCOME_EMAIL_TEMPLATE_ID/g" $CONFFILENAME

src/main/java/com/appirio/tech/core/service/identity/IdentityApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void run(IdentityConfiguration configuration, Environment environment) th
234234
userResource.setAuth0Client(configuration.getAuth0()); // TODO: constructor
235235
userResource.setDomain(configuration.getAuthDomain());
236236
userResource.setSendgridTemplateId(Utils.getString("sendGridTemplateId"));
237+
userResource.setSendgridWelcomeTemplateId(Utils.getString("sendGridWelcomeTemplateId"));
237238
// this secret _used_ to be different from the one used in AuthorizationResource.
238239
// it _was_ the secret x2. (userResource.setSecret(getSecret()+getSecret());)
239240
// we assume this was done to further limit the usability of the oneTimeToken generated in userResource

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public class UserResource implements GetResource<User>, DDLResource<User> {
104104
private String domain;
105105

106106
private String sendgridTemplateId;
107+
108+
private String sendgridWelcomeTemplateId;
107109

108110
protected UserDAO userDao;
109111

@@ -1742,10 +1744,19 @@ public String getSendgridTemplateId() {
17421744
return sendgridTemplateId;
17431745
}
17441746

1747+
public void setSendgridWelcomeTemplateId(String sendgridWelcomeTemplateId) {
1748+
this.sendgridWelcomeTemplateId = sendgridWelcomeTemplateId;
1749+
}
1750+
1751+
public String getSendgridWelcomeTemplateId() {
1752+
return sendgridWelcomeTemplateId;
1753+
}
1754+
17451755
public void setSendgridTemplateId(String sendgridTemplateId) {
17461756
this.sendgridTemplateId = sendgridTemplateId;
17471757
}
17481758

1759+
17491760
public String getSecret() {
17501761
return secret;
17511762
}
@@ -1816,6 +1827,38 @@ private void sendActivationEmailEvent(User user, String redirectUrl) {
18161827
logger.error("Error occured while publishing the events to new kafka.");
18171828
}
18181829
}
1830+
1831+
private void sendWelcomeEmailEvent(User user) {
1832+
1833+
EventMessage msg = EventMessage.getDefault();
1834+
msg.setTopic("external.action.email");
1835+
1836+
Map<String,Object> payload = new LinkedHashMap<String,Object>();
1837+
1838+
Map<String,Object> data = new LinkedHashMap<String,Object>();
1839+
data.put("handle", user.getHandle());
1840+
1841+
payload.put("data", data);
1842+
1843+
Map<String,Object> from = new LinkedHashMap<String,Object>();
1844+
from.put("email", String.format("Topcoder <noreply@%s>", getDomain()));
1845+
payload.put("from", from);
1846+
1847+
payload.put("version", "v3");
1848+
payload.put("sendgrid_template_id", this.getSendgridWelcomeTemplateId());
1849+
1850+
ArrayList<String> recipients = new ArrayList<String>();
1851+
recipients.add(user.getEmail());
1852+
1853+
payload.put("recipients", recipients);
1854+
1855+
msg.setPayload(payload);
1856+
try {
1857+
this.eventBusServiceClient.reFireEvent(msg);
1858+
} catch (Exception e) {
1859+
logger.error("Error occured while publishing the events to new kafka.");
1860+
}
1861+
}
18191862

18201863
protected NotificationPayload createActivationNotificationPayload(User user, String redirectUrl) {
18211864
//If for Connect registration, send activation email with activation code only.
@@ -1834,6 +1877,7 @@ protected void notifyPasswordReset(User user, String resetToken, String resetPas
18341877
protected void notifyWelcome(User user) {
18351878
publishNotificationEvent(
18361879
new NotificationPayload.WelcomePayload(user).getMailRepresentation());
1880+
sendWelcomeEmailEvent(user);
18371881
}
18381882

18391883
protected void publishNotificationEvent(MailRepresentation mail) {
@@ -1871,8 +1915,6 @@ protected void publishEvent(String topic, Object payload) {
18711915
logger.error(String.format("Failed to convert the payload - %s", payload), e);
18721916
}
18731917

1874-
1875-
18761918
}
18771919

18781920
/**

src/main/resources/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ context:
1212
passwordHashKey: @application.password.key@
1313
ssoTokenSalt: @application.ssotoken.salt@
1414
sendGridTemplateId: @application.sendgrid.template.id@
15+
sendGridWelcomeTemplateId: @application.sendgrid.welcome.template.id@
1516
jwtExpirySeconds: 600
1617
cookieExpirySeconds: 7776000
1718

token.properties.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#sendgrid
1111
@application.sendgrid.template.id@={{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID}}
12+
@application.sendgrid.welcome.template.id@={{SENDGRID_WELCOME_EMAIL_TEMPLATE_ID}}
1213

1314
@ldap.host@={{LDAP_SERVER}}
1415
@ldap.port@=389

0 commit comments

Comments
 (0)