diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/ContactTracingController.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/ContactTracingController.java index f3f445b8..1e9dd6f6 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/controller/ContactTracingController.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/ContactTracingController.java @@ -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> filterContactList(Collection> contacts, String type) { + private List> filterContactList(Collection> contacts, String type) { List> filteredList = new ArrayList<>(); for (Contact contact : contacts) { if (type.equals("students") && contact.getContact().getEmail().contains("@stud.hs-mannheim.de")) { diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/CtController.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/CtController.java index 1612426f..9fce4d7a 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/controller/CtController.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/CtController.java @@ -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; @@ -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"; } @@ -335,6 +340,7 @@ public String showFaq(Model model) { ArrayList questions = faqs.get("questions"); model.addAttribute("questions", questions); model.addAttribute("answers", answers); + model.addAttribute("supportMailAddress", MailAddress.parse(supportMailAddress)); return "faq"; } diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/ErrorController.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/ErrorController.java index 7582a44e..749128f3 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/controller/ErrorController.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/ErrorController.java @@ -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; @@ -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") @@ -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); @@ -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"; } diff --git a/src/main/java/de/hs_mannheim/informatik/ct/util/MailAddress.java b/src/main/java/de/hs_mannheim/informatik/ct/util/MailAddress.java new file mode 100644 index 00000000..9ef6e8a8 --- /dev/null +++ b/src/main/java/de/hs_mannheim/informatik/ct/util/MailAddress.java @@ -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 { + 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 split(String data, String delimiter){ + return Arrays.asList(data.split(delimiter)); + } + + private static String joinWithoutLast(List data, String glue){ + String domain = data.get(0); + for(int i=1;i < data.size() - 1;i++){ + domain += glue + data.get(i); + } + return domain; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ff41255f..90227c47 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index 1aa5cc95..939ffacb 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -13,7 +13,7 @@
Es ist ein Fehler aufgetreten!
Leider ist uns dieser Fehler nicht bekannt. Bitte melden Sie ihn an: -
diff --git a/src/main/resources/templates/faq.html b/src/main/resources/templates/faq.html index af25d55e..bd0ba2e1 100644 --- a/src/main/resources/templates/faq.html +++ b/src/main/resources/templates/faq.html @@ -28,7 +28,7 @@

Frequently Asked Questions

Bei weiteren Fragen kontaktieren Sie uns gerne per E-Mail: -
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 73934d72..ad859f3c 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -82,7 +82,7 @@
Ansprechpartner
  • Bei Interesse an der Software oder Rückfragen dazu: -