optimized mails

This commit is contained in:
Jottyfan 2022-12-17 18:01:46 +01:00
parent 028c4d4fd4
commit be0859b93f
6 changed files with 182 additions and 145 deletions

View File

@ -203,22 +203,27 @@ public class PersonGateway {
String campNameWithYear = lrw.getString("campNameWithYear"); String campNameWithYear = lrw.getString("campNameWithYear");
String email = lrw.getString("oldEmail"); String email = lrw.getString("oldEmail");
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
String subject = "allgemeine Nachricht vom Buchungsportal der Onkel-Werner-Freizeiten";
Boolean sendMail = false;
if (acceptNew == null) { if (acceptNew == null) {
if (acceptOld != null) { if (acceptOld != null) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde zurückgesetzt")
.toString();
buf = new StringBuilder("Die Bestätigung der Anmeldung von "); buf = new StringBuilder("Die Bestätigung der Anmeldung von ");
buf.append(bean.getForename()); buf.append(bean.getForename());
buf.append(" "); buf.append(" ");
buf.append(bean.getSurname()); buf.append(bean.getSurname());
buf.append(" zur Freizeit "); buf.append(" zur Freizeit ");
buf.append(campNameWithYear); buf.append(campNameWithYear);
buf.append(" wurde von "); buf.append(" wurde wieder zurückgezogen.");
buf.append(registrator);
buf.append(" wieder zurückgezogen.");
buf.append( buf.append(
" Möglicherweise wurde die Anmeldung versehentlich bestätigt? Deine Anmeldung befindet sich jetzt wieder auf der Warteliste."); " Möglicherweise wurde die Anmeldung versehentlich bestätigt? Deine Anmeldung befindet sich jetzt wieder auf der Warteliste.");
sendMail = true;
} }
} else if (acceptNew == true) { } else if (acceptNew == true) {
if (acceptOld == null || !acceptOld) { if (acceptOld == null || !acceptOld) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde bestätigt")
.toString();
buf = new StringBuilder("Die Anmeldung von "); buf = new StringBuilder("Die Anmeldung von ");
buf.append(bean.getForename()); buf.append(bean.getForename());
buf.append(" "); buf.append(" ");
@ -226,10 +231,13 @@ public class PersonGateway {
buf.append(" zur Freizeit "); buf.append(" zur Freizeit ");
buf.append(campNameWithYear); buf.append(campNameWithYear);
buf.append(" wurde bestätigt. Melde Dich jetzt unter https://www.onkelwernerfreizeiten.de/camporganizer an,"); buf.append(" wurde bestätigt. Melde Dich jetzt unter https://www.onkelwernerfreizeiten.de/camporganizer an,");
buf.append(" um die Bestätigungen herunterzuladen."); buf.append(" um die zu unterschreibenden Dokumente herunterzuladen, auszudrucken und uns zukommen zu lassen.");
sendMail = true;
} }
} else if (acceptNew == false) { } else if (acceptNew == false) {
if (acceptOld == null || acceptOld) { if (acceptOld == null || acceptOld) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde abgelehnt")
.toString();
buf = new StringBuilder("Die Anmeldung von "); buf = new StringBuilder("Die Anmeldung von ");
buf.append(bean.getForename()); buf.append(bean.getForename());
buf.append(" "); buf.append(" ");
@ -239,15 +247,18 @@ public class PersonGateway {
buf.append(" wurde leider abgelehnt."); buf.append(" wurde leider abgelehnt.");
buf.append( buf.append(
" Möglicherweise ist sie schon ausgebucht? Deine Anmeldung befindet sich jetzt auf der Nachrückerliste."); " Möglicherweise ist sie schon ausgebucht? Deine Anmeldung befindet sich jetzt auf der Nachrückerliste.");
sendMail = true;
} }
} }
Set<String> to = new HashSet<>(); if (sendMail) {
to.add(email); Set<String> to = new HashSet<>();
to.add(bean.getEmail()); to.add(email);
try { to.add(bean.getEmail());
mailRepository.sendMail(to, buf.toString()); // no matter if the sending works, do the persistence anyway try {
} catch (Exception e) { mailRepository.sendMail(to, subject, buf.toString()); // no matter if the sending works
LOGGER.error(e.getMessage(), e); } catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
} }
return lrw.getCounter(); return lrw.getCounter();
} }

View File

@ -35,13 +35,14 @@ public class MailRepository {
* nothing * nothing
* *
* @param to the email addresses * @param to the email addresses
* @param subject the subject
* @param message the message * @param message the message
*/ */
public void sendMail(Set<String> to, String message) { public void sendMail(Set<String> to, String subject, String message) {
if (to != null && to.size() > 0) { if (to != null && to.size() > 0) {
if (username != null && !username.isBlank()) { if (username != null && !username.isBlank()) {
try { try {
sendMail(to, message, username); sendMail(to, subject, message, username);
} catch (MessagingException e) { } catch (MessagingException e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
} }
@ -58,11 +59,12 @@ public class MailRepository {
* send the email * send the email
* *
* @param to the recipients * @param to the recipients
* @param subject the subject
* @param message the message * @param message the message
* @param from the username of the email account * @param from the username of the email account
* @throws MessagingException * @throws MessagingException
*/ */
private void sendMail(Set<String> to, String message, String from) throws MessagingException { private void sendMail(Set<String> to, String subject, String message, String from) throws MessagingException {
if (to == null || to.size() < 1) { if (to == null || to.size() < 1) {
throw new MessagingException("no recipient in " + to); throw new MessagingException("no recipient in " + to);
} }
@ -70,7 +72,7 @@ public class MailRepository {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED, MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name()); StandardCharsets.UTF_8.name());
helper.setFrom(from); helper.setFrom(from);
helper.setSubject("Information zu Deiner Anmeldung zur Onkel Werner Freizeit"); helper.setSubject(subject);
helper.setText(message, false); helper.setText(message, false);
helper.setTo(to.toArray(new String[] {})); helper.setTo(to.toArray(new String[] {}));
javaMailSender.send(mimeMessage); javaMailSender.send(mimeMessage);

View File

@ -333,3 +333,17 @@ div {
.mytoggle_btn:hover { .mytoggle_btn:hover {
background-color: #abcdef; background-color: #abcdef;
} }
.loading {
position: absolute;
background: rgba(0, 0, 0, 0.5);
color: white;
font-weight: bolder;
font-size: xx-large;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
text-align: center;
padding-top: 45vh;
}

View File

@ -0,0 +1,9 @@
progress = {
start : function(zin) {
zin = zin || 1000;
$("body").append("<div id=\"requestopen\" class=\"loading\" style=\"z-index: " + zin + " !important\"><i class=\"fa fa-spinner fa-pulse\"></i></div>");
},
stop : function() {
$("#requestopen").remove();
}
}

View File

@ -5,134 +5,134 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head> </head>
<body> <body>
<th:block layout:fragment="header"> <th:block layout:fragment="header">
<ul class="navbar-nav mb-2 mb-lg-0"> <ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item"><a th:href="@{/}" class="btn btn-secondary btn-icon-silent">Hauptseite</a></li> <li class="nav-item"><a th:href="@{/}" class="btn btn-secondary btn-icon-silent">Hauptseite</a></li>
</ul> </ul>
<ul class="navbar-nav mb-2 mb-lg-0"> <ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item"><a th:href="@{/confirmation}" class="btn btn-secondary btn-icon-silent">Anmeldungen</a></li> <li class="nav-item"><a th:href="@{/confirmation}" class="btn btn-secondary btn-icon-silent">Anmeldungen</a></li>
</ul> </ul>
</th:block> </th:block>
<th:block layout:fragment="content"> <th:block layout:fragment="content">
<div class="mainpage"> <div class="mainpage">
<div class="container" style="max-width: 100%" sec:authorize="hasRole('registrator')"> <div class="container" style="max-width: 100%" sec:authorize="hasRole('registrator')">
<form action="#" th:action="@{/confirmation/person/update}" th:object="${person}" method="post" th:if="${person != null}"> <form action="#" th:action="@{/confirmation/person/update}" th:object="${person}" method="post" th:if="${person != null}">
<div class="row mb-2"> <div class="row mb-2">
<label for="outputPk" class="col-sm-2 col-form-label">ID</label> <label for="outputPk" class="col-sm-2 col-form-label">ID</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{pk}" class="outputPk form-control locked"></span> <input type="text" th:field="*{pk}" class="outputPk form-control locked"></span>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputForename" class="col-sm-2 col-form-label">Vorname</label> <label for="inputForename" class="col-sm-2 col-form-label">Vorname</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{forename}" class="inputForename form-control" /> <input type="text" th:field="*{forename}" class="inputForename form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputSurname" class="col-sm-2 col-form-label">Nachname</label> <label for="inputSurname" class="col-sm-2 col-form-label">Nachname</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{surname}" class="inputSurname form-control" /> <input type="text" th:field="*{surname}" class="inputSurname form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputStreet" class="col-sm-2 col-form-label">Straße</label> <label for="inputStreet" class="col-sm-2 col-form-label">Straße</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{street}" class="inputStreet form-control" /> <input type="text" th:field="*{street}" class="inputStreet form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputZip" class="col-sm-2 col-form-label">PLZ</label> <label for="inputZip" class="col-sm-2 col-form-label">PLZ</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{zip}" class="inputZip form-control" /> <input type="text" th:field="*{zip}" class="inputZip form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputCity" class="col-sm-2 col-form-label">Ort</label> <label for="inputCity" class="col-sm-2 col-form-label">Ort</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{city}" class="inputCity form-control" /> <input type="text" th:field="*{city}" class="inputCity form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputBirthdate" class="col-sm-2 col-form-label">Geburtstag (TODO)</label> <label for="inputBirthdate" class="col-sm-2 col-form-label">Geburtstag (TODO)</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="date" th:field="*{birthdate}" class="inputBirthdate form-control" /> <input type="date" th:field="*{birthdate}" class="inputBirthdate form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputSex" class="col-sm-2 col-form-label">Geschlecht</label> <label for="inputSex" class="col-sm-2 col-form-label">Geschlecht</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-select" th:field="*{sex}"> <select class="form-select" th:field="*{sex}">
<option value="male">männlich</option> <option value="male">männlich</option>
<option value="female">weiblich</option> <option value="female">weiblich</option>
</select> </select>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputPhone" class="col-sm-2 col-form-label">Telefon</label> <label for="inputPhone" class="col-sm-2 col-form-label">Telefon</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" th:field="*{phone}" class="inputPhone form-control" /> <input type="text" th:field="*{phone}" class="inputPhone form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputEmail" class="col-sm-2 col-form-label">E-Mail</label> <label for="inputEmail" class="col-sm-2 col-form-label">E-Mail</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="email" th:field="*{email}" class="inputEmail form-control" /> <input type="email" th:field="*{email}" class="inputEmail form-control" />
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="outputCamp" class="col-sm-2 col-form-label">Freizeit</label> <label for="outputCamp" class="col-sm-2 col-form-label">Freizeit</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-select locked" th:field="*{fkCamp}" disabled="disabled"> <select class="form-select locked" th:field="*{fkCamp}" disabled="disabled">
<option th:each="c : ${camps}" th:value="${c.pk}" th:text="${c.name} + ' ' + ${#temporals.format(c.arrive, 'yyyy')} + ' in ' + ${c.location}"></option> <option th:each="c : ${camps}" th:value="${c.pk}" th:text="${c.name} + ' ' + ${#temporals.format(c.arrive, 'yyyy')} + ' in ' + ${c.location}"></option>
</select> </select>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="outputCamprole" class="col-sm-2 col-form-label">Rolle</label> <label for="outputCamprole" class="col-sm-2 col-form-label">Rolle</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="outputCamprole form-select" th:field="*{camprole}"> <select class="outputCamprole form-select" th:field="*{camprole}">
<option value="student">Teilnehmer</option> <option value="student">Teilnehmer</option>
<option value="teacher">Mitarbeiter</option> <option value="teacher">Mitarbeiter</option>
<option value="director">Leiter</option> <option value="director">Leiter</option>
<option value="feeder">Küchenteam</option> <option value="feeder">Küchenteam</option>
</select> </select>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputComment" class="col-sm-2 col-form-label">Kommentar</label> <label for="inputComment" class="col-sm-2 col-form-label">Kommentar</label>
<div class="col-sm-10"> <div class="col-sm-10">
<textarea th:field="*{comment}" class="inputComment form-control"></textarea> <textarea th:field="*{comment}" class="inputComment form-control"></textarea>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="outputAnno" class="col-sm-2 col-form-label">Anmerkungen</label> <label for="outputAnno" class="col-sm-2 col-form-label">Anmerkungen</label>
<div class="col-sm-10"> <div class="col-sm-10">
<pre class="form-control locked" th:text="${annotations}"></pre> <pre class="form-control locked" th:text="${annotations}"></pre>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label">Status</label> <label for="inputAccept" class="col-sm-2 col-form-label">Status</label>
<div class="col-sm-10"> <div class="col-sm-10">
<div class="form-group"> <div class="form-group">
<input type="radio" class="btn-check" id="accept1" name="accept1" value="" th:field="*{accept}" /> <label class="btn btn-outline-primary" for="accept1"><i <input type="radio" class="btn-check" id="accept1" name="accept1" value="" th:field="*{accept}" /> <label class="btn btn-outline-primary" for="accept1"><i
class="fas fa-question"></i>&nbsp;offen</label> <input type="radio" class="btn-check" id="accept2" name="accept2" value="true" th:field="*{accept}" /> <label class="btn btn-outline-success" class="fas fa-question"></i>&nbsp;offen</label> <input type="radio" class="btn-check" id="accept2" name="accept2" value="true" th:field="*{accept}" /> <label class="btn btn-outline-success"
for="accept2"><i class="fas fa-check"></i>&nbsp;bestätigt</label> <input type="radio" class="btn-check" id="accept3" name="accept3" value="false" th:field="*{accept}" /> <label for="accept2"><i class="fas fa-check"></i>&nbsp;bestätigt</label> <input type="radio" class="btn-check" id="accept3" name="accept3" value="false" th:field="*{accept}" /> <label
class="btn btn-outline-danger" for="accept3"><i class="fas fa-ban"></i>&nbsp;abgelehnt</label> class="btn btn-outline-danger" for="accept3"><i class="fas fa-ban"></i>&nbsp;abgelehnt</label>
</div> </div>
</div> </div>
</div> </div>
<div class="row mb-2"> <div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label"></label> <label for="inputAccept" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10"> <div class="col-sm-10">
<button type="submit" class="btn btn-primary">Ok</button> <button type="submit" class="btn btn-primary" onclick="progress.start()">Ok</button>
<a th:href="@{/confirmation/}" class="btn btn-secondary">Abbrechen</a> <a th:href="@{/confirmation/}" class="btn btn-secondary">Abbrechen</a>
</div> </div>
</div> </div>
</form> </form>
<div th:if="${person == null}" class="error">In der Datenbank wurde keine Person mit entsprechender ID gefunden.</div> <div th:if="${person == null}" class="error">In der Datenbank wurde keine Person mit entsprechender ID gefunden.</div>
</div> </div>
</div> </div>
</th:block> </th:block>
</body> </body>
</html> </html>

View File

@ -16,6 +16,7 @@
<script th:src="@{/js/dataTables.de.js}"></script> <script th:src="@{/js/dataTables.de.js}"></script>
<script th:src="@{/js/mytoggle.js}"></script> <script th:src="@{/js/mytoggle.js}"></script>
<script th:src="@{/js/myAjax.js}"></script> <script th:src="@{/js/myAjax.js}"></script>
<script th:src="@{/js/progress.js}"></script>
<th:block layout:fragment="libs"></th:block> <th:block layout:fragment="libs"></th:block>
</head> </head>
<body> <body>