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 email = lrw.getString("oldEmail");
StringBuilder buf = new StringBuilder();
String subject = "allgemeine Nachricht vom Buchungsportal der Onkel-Werner-Freizeiten";
Boolean sendMail = false;
if (acceptNew == 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.append(bean.getForename());
buf.append(" ");
buf.append(bean.getSurname());
buf.append(" zur Freizeit ");
buf.append(campNameWithYear);
buf.append(" wurde von ");
buf.append(registrator);
buf.append(" wieder zurückgezogen.");
buf.append(" wurde wieder zurückgezogen.");
buf.append(
" Möglicherweise wurde die Anmeldung versehentlich bestätigt? Deine Anmeldung befindet sich jetzt wieder auf der Warteliste.");
sendMail = true;
}
} else if (acceptNew == true) {
if (acceptOld == null || !acceptOld) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde bestätigt")
.toString();
buf = new StringBuilder("Die Anmeldung von ");
buf.append(bean.getForename());
buf.append(" ");
@ -226,10 +231,13 @@ public class PersonGateway {
buf.append(" zur Freizeit ");
buf.append(campNameWithYear);
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) {
if (acceptOld == null || acceptOld) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde abgelehnt")
.toString();
buf = new StringBuilder("Die Anmeldung von ");
buf.append(bean.getForename());
buf.append(" ");
@ -239,15 +247,18 @@ public class PersonGateway {
buf.append(" wurde leider abgelehnt.");
buf.append(
" Möglicherweise ist sie schon ausgebucht? Deine Anmeldung befindet sich jetzt auf der Nachrückerliste.");
sendMail = true;
}
}
Set<String> to = new HashSet<>();
to.add(email);
to.add(bean.getEmail());
try {
mailRepository.sendMail(to, buf.toString()); // no matter if the sending works, do the persistence anyway
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
if (sendMail) {
Set<String> to = new HashSet<>();
to.add(email);
to.add(bean.getEmail());
try {
mailRepository.sendMail(to, subject, buf.toString()); // no matter if the sending works
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
return lrw.getCounter();
}

View File

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

View File

@ -333,3 +333,17 @@ div {
.mytoggle_btn:hover {
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" />
</head>
<body>
<th:block layout:fragment="header">
<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>
</ul>
<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>
</ul>
</th:block>
<th:block layout:fragment="content">
<div class="mainpage">
<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}">
<div class="row mb-2">
<label for="outputPk" class="col-sm-2 col-form-label">ID</label>
<div class="col-sm-10">
<input type="text" th:field="*{pk}" class="outputPk form-control locked"></span>
</div>
</div>
<div class="row mb-2">
<label for="inputForename" class="col-sm-2 col-form-label">Vorname</label>
<div class="col-sm-10">
<input type="text" th:field="*{forename}" class="inputForename form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputSurname" class="col-sm-2 col-form-label">Nachname</label>
<div class="col-sm-10">
<input type="text" th:field="*{surname}" class="inputSurname form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputStreet" class="col-sm-2 col-form-label">Straße</label>
<div class="col-sm-10">
<input type="text" th:field="*{street}" class="inputStreet form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputZip" class="col-sm-2 col-form-label">PLZ</label>
<div class="col-sm-10">
<input type="text" th:field="*{zip}" class="inputZip form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputCity" class="col-sm-2 col-form-label">Ort</label>
<div class="col-sm-10">
<input type="text" th:field="*{city}" class="inputCity form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputBirthdate" class="col-sm-2 col-form-label">Geburtstag (TODO)</label>
<div class="col-sm-10">
<input type="date" th:field="*{birthdate}" class="inputBirthdate form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputSex" class="col-sm-2 col-form-label">Geschlecht</label>
<div class="col-sm-10">
<select class="form-select" th:field="*{sex}">
<option value="male">männlich</option>
<option value="female">weiblich</option>
</select>
</div>
</div>
<div class="row mb-2">
<label for="inputPhone" class="col-sm-2 col-form-label">Telefon</label>
<div class="col-sm-10">
<input type="text" th:field="*{phone}" class="inputPhone form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputEmail" class="col-sm-2 col-form-label">E-Mail</label>
<div class="col-sm-10">
<input type="email" th:field="*{email}" class="inputEmail form-control" />
</div>
</div>
<div class="row mb-2">
<label for="outputCamp" class="col-sm-2 col-form-label">Freizeit</label>
<div class="col-sm-10">
<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>
</select>
</div>
</div>
<div class="row mb-2">
<label for="outputCamprole" class="col-sm-2 col-form-label">Rolle</label>
<div class="col-sm-10">
<select class="outputCamprole form-select" th:field="*{camprole}">
<option value="student">Teilnehmer</option>
<option value="teacher">Mitarbeiter</option>
<option value="director">Leiter</option>
<option value="feeder">Küchenteam</option>
</select>
</div>
</div>
<div class="row mb-2">
<label for="inputComment" class="col-sm-2 col-form-label">Kommentar</label>
<div class="col-sm-10">
<textarea th:field="*{comment}" class="inputComment form-control"></textarea>
</div>
</div>
<div class="row mb-2">
<label for="outputAnno" class="col-sm-2 col-form-label">Anmerkungen</label>
<div class="col-sm-10">
<pre class="form-control locked" th:text="${annotations}"></pre>
</div>
</div>
<div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label">Status</label>
<div class="col-sm-10">
<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
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
class="btn btn-outline-danger" for="accept3"><i class="fas fa-ban"></i>&nbsp;abgelehnt</label>
</div>
</div>
</div>
<div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">Ok</button>
<a th:href="@{/confirmation/}" class="btn btn-secondary">Abbrechen</a>
</div>
</div>
</form>
<div th:if="${person == null}" class="error">In der Datenbank wurde keine Person mit entsprechender ID gefunden.</div>
</div>
</div>
</th:block>
<th:block layout:fragment="header">
<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>
</ul>
<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>
</ul>
</th:block>
<th:block layout:fragment="content">
<div class="mainpage">
<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}">
<div class="row mb-2">
<label for="outputPk" class="col-sm-2 col-form-label">ID</label>
<div class="col-sm-10">
<input type="text" th:field="*{pk}" class="outputPk form-control locked"></span>
</div>
</div>
<div class="row mb-2">
<label for="inputForename" class="col-sm-2 col-form-label">Vorname</label>
<div class="col-sm-10">
<input type="text" th:field="*{forename}" class="inputForename form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputSurname" class="col-sm-2 col-form-label">Nachname</label>
<div class="col-sm-10">
<input type="text" th:field="*{surname}" class="inputSurname form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputStreet" class="col-sm-2 col-form-label">Straße</label>
<div class="col-sm-10">
<input type="text" th:field="*{street}" class="inputStreet form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputZip" class="col-sm-2 col-form-label">PLZ</label>
<div class="col-sm-10">
<input type="text" th:field="*{zip}" class="inputZip form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputCity" class="col-sm-2 col-form-label">Ort</label>
<div class="col-sm-10">
<input type="text" th:field="*{city}" class="inputCity form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputBirthdate" class="col-sm-2 col-form-label">Geburtstag (TODO)</label>
<div class="col-sm-10">
<input type="date" th:field="*{birthdate}" class="inputBirthdate form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputSex" class="col-sm-2 col-form-label">Geschlecht</label>
<div class="col-sm-10">
<select class="form-select" th:field="*{sex}">
<option value="male">männlich</option>
<option value="female">weiblich</option>
</select>
</div>
</div>
<div class="row mb-2">
<label for="inputPhone" class="col-sm-2 col-form-label">Telefon</label>
<div class="col-sm-10">
<input type="text" th:field="*{phone}" class="inputPhone form-control" />
</div>
</div>
<div class="row mb-2">
<label for="inputEmail" class="col-sm-2 col-form-label">E-Mail</label>
<div class="col-sm-10">
<input type="email" th:field="*{email}" class="inputEmail form-control" />
</div>
</div>
<div class="row mb-2">
<label for="outputCamp" class="col-sm-2 col-form-label">Freizeit</label>
<div class="col-sm-10">
<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>
</select>
</div>
</div>
<div class="row mb-2">
<label for="outputCamprole" class="col-sm-2 col-form-label">Rolle</label>
<div class="col-sm-10">
<select class="outputCamprole form-select" th:field="*{camprole}">
<option value="student">Teilnehmer</option>
<option value="teacher">Mitarbeiter</option>
<option value="director">Leiter</option>
<option value="feeder">Küchenteam</option>
</select>
</div>
</div>
<div class="row mb-2">
<label for="inputComment" class="col-sm-2 col-form-label">Kommentar</label>
<div class="col-sm-10">
<textarea th:field="*{comment}" class="inputComment form-control"></textarea>
</div>
</div>
<div class="row mb-2">
<label for="outputAnno" class="col-sm-2 col-form-label">Anmerkungen</label>
<div class="col-sm-10">
<pre class="form-control locked" th:text="${annotations}"></pre>
</div>
</div>
<div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label">Status</label>
<div class="col-sm-10">
<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
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
class="btn btn-outline-danger" for="accept3"><i class="fas fa-ban"></i>&nbsp;abgelehnt</label>
</div>
</div>
</div>
<div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10">
<button type="submit" class="btn btn-primary" onclick="progress.start()">Ok</button>
<a th:href="@{/confirmation/}" class="btn btn-secondary">Abbrechen</a>
</div>
</div>
</form>
<div th:if="${person == null}" class="error">In der Datenbank wurde keine Person mit entsprechender ID gefunden.</div>
</div>
</div>
</th:block>
</body>
</html>
</html>

View File

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