Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static class TracingColumn {
* @param type String of the filter type (students/ staff/ guests)
* @return filtered List of Contacts
*/
private List<Contact<?>> filterContactList(Collection<Contact<? extends Visit>> contacts, String type) {
private List<Contact<? extends Visit>> filterContactList(Collection<Contact<? extends Visit>> contacts, String type) {
List<Contact<?>> filteredList = new ArrayList<>();
for (Contact<? extends Visit> contact : contacts) {
if (type.equals("students") && contact.getContact().getEmail().contains("@stud.hs-mannheim.de")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import de.hs_mannheim.informatik.ct.util.MailAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
Expand Down Expand Up @@ -100,8 +101,12 @@ public class CtController {
@Value("${hostname}")
private String host;

@Value("${support_mail_address}")
private String supportMailAddress;

@RequestMapping("/")
public String home(Model model) {
model.addAttribute("supportMailAddress", MailAddress.parse(supportMailAddress));
model.addAttribute("freeLearnerPlaces", roomVisitService.getRemainingStudyPlaces());
return "index";
}
Expand Down Expand Up @@ -335,6 +340,7 @@ public String showFaq(Model model) {
ArrayList<String> questions = faqs.get("questions");
model.addAttribute("questions", questions);
model.addAttribute("answers", answers);
model.addAttribute("supportMailAddress", MailAddress.parse(supportMailAddress));
return "faq";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;

import de.hs_mannheim.informatik.ct.util.MailAddress;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -42,6 +44,11 @@
@ControllerAdvice
@Slf4j
public class ErrorController {

@Value("${support_mail_address}")
private String supportMailAddress;


@ExceptionHandler({RoomController.RoomNotFoundException.class})
@ResponseStatus(value = HttpStatus.NOT_FOUND)
// @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Room not found")
Expand Down Expand Up @@ -124,7 +131,7 @@ public String handleInvalidRoomPinException(Model model) {
@RequestMapping("/error")
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
// @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "error")
public String handleError(HttpServletRequest request) {
public String handleError(Model model, HttpServletRequest request) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
log.error("Request Status: {}", status);

Expand All @@ -135,17 +142,18 @@ public String handleError(HttpServletRequest request) {
}

}
model.addAttribute("supportMailAddress", MailAddress.parse(supportMailAddress));
return "error";
}

@ExceptionHandler({Exception.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
// @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "unknown error")
public String anyException(Exception e) {
public String anyException(Model model, Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
log.error(sw.toString());

log.error(sw.toString());
model.addAttribute("supportMailAddress", MailAddress.parse(supportMailAddress));
return "error";
}

Expand Down
56 changes: 56 additions & 0 deletions src/main/java/de/hs_mannheim/informatik/ct/util/MailAddress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.hs_mannheim.informatik.ct.util;

import de.hs_mannheim.informatik.ct.persistence.InvalidEmailException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import lombok.var;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@AllArgsConstructor @Getter
@Slf4j
public class MailAddress {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I getting this right, that this class and the whole parsing is only done to decompose the mail address for the mail obfuscation used in the frontend? Wouldn't it be easier to decompose this manually in the properties file and access the elements from the frontend directly? (like so: https://stackoverflow.com/questions/56102116/access-application-properties-value-in-thymeleaf-template)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you could also enter the email address already split into the properties. I thought that might be a bit more comfortable in the configuration if the splitting happens automatically.

private String mailAddress;
private String name;
private String domain;
private String tld;

private static final String EMAIL_REGEX = "(.*)@(.*)\\.(.*)$";
private static final String DEFAULT_INVALID_MAIL = "invalid-email@invalid.org";

public static MailAddress parse(String mailAddress) {
val match = splitMailAddress(mailAddress);
val name = match.group(1);
val domain = match.group(2);
val tld = match.group(3);
return new MailAddress(mailAddress, name, domain, tld);
}

private static Matcher splitMailAddress(String mailAddress){
Matcher match = Pattern.compile(EMAIL_REGEX).matcher(mailAddress);
if(!match.matches()) {
match = Pattern.compile(EMAIL_REGEX).matcher(DEFAULT_INVALID_MAIL);
log.error("support mail address '"+mailAddress+"' is invalid");
}
return match;
}

private static List<String> split(String data, String delimiter){
return Arrays.asList(data.split(delimiter));
}

private static String joinWithoutLast(List<String> data, String glue){
String domain = data.get(0);
for(int i=1;i < data.size() - 1;i++){
domain += glue + data.get(i);
}
return domain;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ server_env=dev
allow_full_room_checkIn=true
warning_for_full_room=false
check_3G_status=false
support_mail_address=ctt-admin@hs-mannheim.de

spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:./h2db/database;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div>Es ist ein Fehler aufgetreten!</div>

<div>Leider ist uns dieser Fehler nicht bekannt. Bitte melden Sie ihn an:
<a href="#" class="crypted" data-name="ctt-admin" data-domain="hs-mannheim" data-tld="de"
<a href="#" class="crypted" th:data-name="${supportMailAddress.name}" th:data-domain="${supportMailAddress.domain}" th:data-tld="${supportMailAddress.tld}"
onclick="window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld; return false;">
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h4>Frequently Asked Questions</h4>
</div>
<div style="margin-top: 50px; margin-bottom: 100px;">
Bei weiteren Fragen kontaktieren Sie uns gerne per E-Mail:
<a href="#" class="crypted" data-name="ctt-admin" data-domain="hs-mannheim" data-tld="de"
<a href="#" class="crypted" th:data-name="${supportMailAddress.name}" th:data-domain="${supportMailAddress.domain}" th:data-tld="${supportMailAddress.tld}"
onclick="window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld; return false;">
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h5>Ansprechpartner</h5>
</a>
</li>
<li>Bei Interesse an der Software oder Rückfragen dazu:
<a href="#" class="crypted" data-name="ctt-admin" data-domain="hs-mannheim" data-tld="de"
<a href="#" class="crypted" th:data-name="${supportMailAddress.name}" th:data-domain="${supportMailAddress.domain}" th:data-tld="${supportMailAddress.tld}"
onclick="window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld; return false;">
</a>
</li>
Expand Down