From a201d9c46d5fcf7a34695ad90bbd3e76bce053b8 Mon Sep 17 00:00:00 2001 From: Laurent Hasson <410503+ldhasson@users.noreply.github.com> Date: Mon, 29 Jul 2024 03:19:31 -0400 Subject: [PATCH] #54 better email logging --- src/wanda/data/User_Data.java | 51 ++++++++++++------- .../servlets/admin/InviteUserServlet.java | 3 +- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/wanda/data/User_Data.java b/src/wanda/data/User_Data.java index fbee538..6bee723 100644 --- a/src/wanda/data/User_Data.java +++ b/src/wanda/data/User_Data.java @@ -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(); } @@ -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() @@ -316,25 +322,34 @@ public void sendInviteEmail() public void run() { super.run(); - StringBuilder sb = new StringBuilder(); - List copyTexts = WebBasics.getInviteUserTexts(); - if (copyTexts != null) + try { - Iterator i = copyTexts.listIterator(); - while (i.hasNext()) + StringBuilder sb = new StringBuilder(); + List copyTexts = WebBasics.getInviteUserTexts(); + if (copyTexts != null) { - sb.append(i.next()); + Iterator i = copyTexts.listIterator(); + while (i.hasNext()) + { + sb.append(i.next()); + } } + sb.append("

Click here to set your password

"); + 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("

Click here to set your password

"); - EMailSender.sendMailUsr(to, cc, bcc, "Set Password: Invited to " + WebBasics.getAppName(), sb.toString(), true, true); } }.start(); } @@ -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); + } } diff --git a/src/wanda/servlets/admin/InviteUserServlet.java b/src/wanda/servlets/admin/InviteUserServlet.java index c0221b5..af521bc 100644 --- a/src/wanda/servlets/admin/InviteUserServlet.java +++ b/src/wanda/servlets/admin/InviteUserServlet.java @@ -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 @@ -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); }