Skip to content

Commit

Permalink
#54 better email logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhasson committed Jul 29, 2024
1 parent 2a36ab2 commit a201d9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
51 changes: 33 additions & 18 deletions src/wanda/data/User_Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public static void inviteUser(Connection C, String email, String firstName, Stri
{
throw new BadRequestException(Errors);
}
LOG.debug("Sending a new invitation email to '" + U.getEmail() + "'.");
U.sendInviteEmail();
}

Expand Down Expand Up @@ -302,8 +303,13 @@ else if (tenantUser.getActive() == false)// TODO change schema for better naming
}
if (isResetPassword == true)
{
LOG.debug("Sending another invitation email to '" + U.getEmail() + "'.");
U.sendInviteEmail();
}
else
{
LOG.debug("NOT SENDING another invitation email to '" + U.getEmail() + "' because U.getLoginCount() = " + U.getLoginCount() + ".");
}
}

public void sendInviteEmail()
Expand All @@ -316,25 +322,34 @@ public void sendInviteEmail()
public void run()
{
super.run();
StringBuilder sb = new StringBuilder();
List<String> copyTexts = WebBasics.getInviteUserTexts();
if (copyTexts != null)
try
{
Iterator<String> i = copyTexts.listIterator();
while (i.hasNext())
StringBuilder sb = new StringBuilder();
List<String> copyTexts = WebBasics.getInviteUserTexts();
if (copyTexts != null)
{
sb.append(i.next());
Iterator<String> i = copyTexts.listIterator();
while (i.hasNext())
{
sb.append(i.next());
}
}
sb.append("<p><a href='");
sb.append(WebBasics.getHostName());
sb.append(WebBasics.getAppPath());
sb.append(WebBasics.getHomePagePath());
sb.append("?action=signUp");
sb.append("&token=");
sb.append(getPswdResetCode());
sb.append("'>Click here to set your password</a></p>");
LOG.debug("Sending email invitation to " + getEmail() + " via thread.");
EMailSender.sendMailUsr(to, cc, bcc, "Set Password: Invited to " + WebBasics.getAppName(), sb.toString(), true, true);
LOG.debug("Sent email invitation to " + getEmail() + " via thread.");
}
catch (Throwable T)
{
LOG.error("Failed sending email to '" + getEmail() + "'.\n", T);
}
sb.append("<p><a href='");
sb.append(WebBasics.getHostName());
sb.append(WebBasics.getAppPath());
sb.append(WebBasics.getHomePagePath());
sb.append("?action=signUp");
sb.append("&token=");
sb.append(getPswdResetCode());
sb.append("'>Click here to set your password</a></p>");
EMailSender.sendMailUsr(to, cc, bcc, "Set Password: Invited to " + WebBasics.getAppName(), sb.toString(), true, true);
}
}.start();
}
Expand Down Expand Up @@ -538,7 +553,7 @@ public long getAlternateRefnum()
}

public String getOrCreatePswdSalt()
{
return TextUtil.isNullOrEmpty(getPswdSalt()) == false ? getPswdSalt() : EncryptionUtil.getToken(8);
}
{
return TextUtil.isNullOrEmpty(getPswdSalt()) == false ? getPswdSalt() : EncryptionUtil.getToken(8);
}
}
3 changes: 2 additions & 1 deletion src/wanda/servlets/admin/InviteUserServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected void justDo(RequestUtil Req, ResponseUtil Res, Connection C, User_Data
Req.addError("refnum", "User not found");
}
Req.throwIfErrors();

LOG.debug("Updating existing user access");
User_Data.updateDetailsAndInvite(C, refnumUser, email, firstName, lastName, roles, appRefnums, tenantRefnumList, oldTenantRefnums);
}
else
Expand All @@ -115,6 +115,7 @@ protected void justDo(RequestUtil Req, ResponseUtil Res, Connection C, User_Data
if (emailUser.read(C))
Req.addError("email", "User already exists with email '" + email + "'");
Req.throwIfErrors();
LOG.debug("Inviting new user");
User_Data.inviteUser(C, email, firstName, lastName, roles, tenantRefnums, appRefnums);
}

Expand Down

0 comments on commit a201d9c

Please sign in to comment.