From 612d3eecaf45a47dd82cf396f9f178c6b3ede389 Mon Sep 17 00:00:00 2001 From: "m.stock" <36995969+maxones25@users.noreply.github.com> Date: Thu, 28 Oct 2021 15:02:47 +0200 Subject: [PATCH 1/9] add class CheckInInterceptor --- .../ct/interceptor/CheckInInterceptor.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java diff --git a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java b/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java new file mode 100644 index 00000000..edf124c8 --- /dev/null +++ b/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java @@ -0,0 +1,83 @@ +package de.hs_mannheim.informatik.ct.controller.interceptor; + +/* + * Corona Tracking Tool der Hochschule Mannheim + * Copyright (C) 2021 Hochschule Mannheim + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import de.hs_mannheim.informatik.ct.controller.Utilities; +import de.hs_mannheim.informatik.ct.model.RoomVisit; +import de.hs_mannheim.informatik.ct.persistence.services.RoomVisitService; +import de.hs_mannheim.informatik.ct.persistence.services.VisitorService; +import de.hs_mannheim.informatik.ct.util.CookieManager; +import lombok.val; +import lombok.var; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +public class CheckInInterceptor implements HandlerInterceptor { + + @Autowired + private VisitorService visitorService; + + @Autowired + private RoomVisitService roomVisitService; + + @Autowired + private Utilities util; + + private static final String CHECKED_IN_COOKIE_NAME = "checkedInEmail"; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ + val cookieManager = new CookieManager(request, response); + var isCheckedIn = false; + val checkedInEmail = cookieManager.getCookieValue(CookieManager.Cookies.CHECKED_IN_EMAIL); + if(checkedInEmail!=null){ + val checkedInRoom = getCheckedInRoomName(checkedInEmail); + if(checkedInRoom!=null){ + isCheckedIn = true; + request.setAttribute("checkedInRoom", checkedInRoom); + }else{ + cookieManager.removeCookie(CookieManager.Cookies.CHECKED_IN_EMAIL); + } + } + request.setAttribute("checkedInEmail", checkedInEmail); + request.setAttribute("isCheckedIn", isCheckedIn); + return true; + } + + private String getCheckedInRoomName(String email){ + List roomVisits = findCurrentRoomVisitsByEmail(email); + return roomVisits.size()>0 ? roomVisits.get(0).getRoom().getName() : null; + } + + private List findCurrentRoomVisitsByEmail(String email){ + List roomVisits = new ArrayList<>(); + val visitor = visitorService.findVisitorByEmail(email); + if(visitor.isPresent()) { + for(val roomVisit : roomVisitService.getCheckedInRoomVisits(visitor.get())){ + roomVisits.add(roomVisit); + } + } + return roomVisits; + } +} \ No newline at end of file From a6988d623636c56b9df61225739eb1997dd56d81 Mon Sep 17 00:00:00 2001 From: "m.stock" <36995969+maxones25@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:00:18 +0200 Subject: [PATCH 2/9] add changes --- .../ct/controller/RoomController.java | 14 +- .../resolver/CookieManagerResolver.java | 51 ++++++ .../services/ContactTracingService.java | 5 +- .../informatik/ct/util/CookieManager.java | 150 ++++++++++++++++++ .../ct/util/ScheduledMaintenanceTasks.java | 2 +- .../informatik/ct/web/WebConfig.java | 51 ++++++ src/main/resources/static/general.css | 40 +++++ src/main/resources/static/main.js | 7 + src/main/resources/templates/layout.html | 12 ++ .../resources/templates/rooms/layout.html | 15 +- .../RoomControllerOverrideTest.java | 6 +- .../ct/end_to_end/RoomControllerTest.java | 14 +- 12 files changed, 349 insertions(+), 18 deletions(-) create mode 100644 src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java create mode 100644 src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java create mode 100644 src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java create mode 100644 src/main/resources/static/general.css create mode 100644 src/main/resources/static/main.js diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java index 31f2863f..34c72dd8 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java @@ -28,6 +28,7 @@ import java.nio.charset.StandardCharsets; import java.util.Optional; +import de.hs_mannheim.informatik.ct.util.CookieManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; @@ -136,7 +137,7 @@ public String checkIn(@PathVariable String roomId, @PostMapping("/checkIn") @Transactional - public String checkIn(@ModelAttribute RoomVisit.Data visitData, Model model) throws UnsupportedEncodingException, InvalidRoomPinException, InvalidEmailException, InvalidExternalUserdataException { + public String checkIn(@ModelAttribute RoomVisit.Data visitData, Model model, CookieManager cookieManager) throws UnsupportedEncodingException, InvalidRoomPinException, InvalidEmailException, InvalidExternalUserdataException { isRoomPinValidOrThrow(visitData); val room = roomService.getRoomOrThrow(visitData.getRoomId()); @@ -167,6 +168,8 @@ public String checkIn(@ModelAttribute RoomVisit.Data visitData, Model model) thr // room manager should always be allowed to check-in // and needs to be checked in before the browser is forwarded to a different page! val visit = roomVisitService.visitRoom(visitor, room); + + cookieManager.addCookie(CookieManager.Cookies.CHECKED_IN_EMAIL, visitorEmail); if (visitData.isPrivileged()) { val encodedVisitorEmail = URLEncoder.encode(visitorEmail, "UTF-8"); @@ -201,7 +204,7 @@ private void isRoomPinValidOrThrow(Data visitData) throws InvalidRoomPinExceptio */ @PostMapping("/checkInOverride") @Transactional - public String checkInWithOverride(@ModelAttribute RoomVisit.Data visitData, Model model) throws + public String checkInWithOverride(@ModelAttribute RoomVisit.Data visitData, Model model, CookieManager cookieManager) throws UnsupportedEncodingException, InvalidEmailException, InvalidExternalUserdataException, InvalidRoomPinException { // TODO: this method is very similar with the normal check-in, maybe this should be refactored? @@ -219,6 +222,9 @@ public String checkInWithOverride(@ModelAttribute RoomVisit.Data visitData, Mode roomVisitService.checkOutVisitor(visitor); val visit = roomVisitService.visitRoom(visitor, room); + + cookieManager.addCookie(CookieManager.Cookies.CHECKED_IN_EMAIL, visitorEmail); + val currentVisitCount = roomVisitService.getVisitorCount(room); visitData = new RoomVisit.Data(visit, currentVisitCount); model.addAttribute("visitData", visitData); @@ -227,9 +233,9 @@ public String checkInWithOverride(@ModelAttribute RoomVisit.Data visitData, Mode } @PostMapping("/checkOut") - public String checkOut(@ModelAttribute RoomVisit.Data visitData) { + public String checkOut(@ModelAttribute RoomVisit.Data visitData, CookieManager cookieManager) { val visitor = getVisitorOrThrow(visitData.getVisitorEmail()); - + cookieManager.removeCookie(CookieManager.Cookies.CHECKED_IN_EMAIL); roomVisitService.checkOutVisitor(visitor); return "redirect:/r/checkedOut"; } diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java new file mode 100644 index 00000000..8fc8ca8e --- /dev/null +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java @@ -0,0 +1,51 @@ +package de.hs_mannheim.informatik.ct.controller.resolver; + +/* + * Corona Tracking Tool der Hochschule Mannheim + * Copyright (C) 2021 Hochschule Mannheim + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import de.hs_mannheim.informatik.ct.util.CookieManager; +import org.springframework.core.MethodParameter; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.method.support.ModelAndViewContainer; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CookieManagerResolver + implements HandlerMethodArgumentResolver { + + @Override + public boolean supportsParameter(MethodParameter methodParameter) { + return methodParameter.getParameter().getType() == CookieManager.class; + } + + @Override + public Object resolveArgument( + MethodParameter methodParameter, + ModelAndViewContainer modelAndViewContainer, + NativeWebRequest nativeWebRequest, + WebDataBinderFactory webDataBinderFactory) throws Exception { + + HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); + HttpServletResponse response = (HttpServletResponse) nativeWebRequest.getNativeResponse(); + + return new CookieManager(request, response); + } +} \ No newline at end of file diff --git a/src/main/java/de/hs_mannheim/informatik/ct/persistence/services/ContactTracingService.java b/src/main/java/de/hs_mannheim/informatik/ct/persistence/services/ContactTracingService.java index 7c5de3d6..5085c6b4 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/persistence/services/ContactTracingService.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/persistence/services/ContactTracingService.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import de.hs_mannheim.informatik.ct.model.Visit; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -35,8 +36,8 @@ public class ContactTracingService { private List> visitServices; @NonNull - public List> getVisitorContacts(@NonNull Visitor visitor) { - val contacts = new ArrayList>(); + public List> getVisitorContacts(@NonNull Visitor visitor) { + val contacts = new ArrayList>(); for (val service : visitServices) { contacts.addAll(service.getVisitorContacts(visitor)); } diff --git a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java new file mode 100644 index 00000000..831cdad4 --- /dev/null +++ b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java @@ -0,0 +1,150 @@ +package de.hs_mannheim.informatik.ct.util; + +/* + * Corona Tracking Tool der Hochschule Mannheim + * Copyright (C) 2021 Hochschule Mannheim + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import lombok.val; +import org.springframework.web.util.WebUtils; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.time.LocalTime; + +public class CookieManager { + private HttpServletRequest request; + private HttpServletResponse response; + + public CookieManager(HttpServletRequest request){ + this.request = request; + } + + public CookieManager(HttpServletRequest request, HttpServletResponse response){ + this(request); + this.response = response; + } + + public static enum Cookies{ + CHECKED_IN_EMAIL("checkedInEmail"); + + private String name; + + private Cookies(String name) { + this.name = name; + } + + public String getName(){ + return this.name; + } + } + + /** + * create a new cookie with a cookie factory + * + * @param cookieType cookie type + * @param value value of the cookie + */ + private Cookie createCookie(Cookies cookieType, String value) { + Cookie cookie = null; + switch (cookieType){ + case CHECKED_IN_EMAIL: + cookie = new CookieBuilder(cookieType.getName(), value) + .maxAge(getSecondsTill(LocalTime.parse(ScheduledMaintenanceTasks.FORCED_END_TIME))) + .build(); + break; + } + return cookie; + } + + /** + * add a cookie to the http response + * + * @param cookieType cookie type + * @param value value of the cookie + */ + public void addCookie(Cookies cookieType, String value) { + val cookie = createCookie(cookieType, value); + response.addCookie(cookie); + } + + /** + * remove a cookie from the http response + * + * @param cookieType cookie type + */ + public void removeCookie(Cookies cookieType) { + Cookie cookie = new Cookie(cookieType.getName(), ""); + cookie.setMaxAge(0); + cookie.setPath("/"); + response.addCookie(cookie); + } + + /** + * get a cookie from http request + * + * @param cookieType cookie type + */ + public String getCookieValue(Cookies cookieType){ + val cookie = WebUtils.getCookie(request, cookieType.getName()); + return cookie!=null ? cookie.getValue() : null; + } + + /** + * remove a cookie from the http response + * + * @param maxAgeEndTime time when the cookie should be invalid + * @return max age of the cookie + */ + private int getSecondsTill(LocalTime maxAgeEndTime){ + int now = LocalTime.now().toSecondOfDay(); + int endTime = maxAgeEndTime.toSecondOfDay(); + int nextDayEndTime = ((24 * 60 * 60) + endTime); + return (now > endTime) ? nextDayEndTime - now : endTime - now; + } + + private static class CookieBuilder{ + private String name, value, path; + private int maxAge; + + public CookieBuilder(String name, String value){ + this.name = name; + this.value = value; + this.path = "/"; + this.maxAge = 0; + } + + public CookieBuilder maxAge(int maxAge){ + this.maxAge = maxAge; + return this; + } + + public CookieBuilder path(String path){ + this.path = path; + return this; + } + + public Cookie build(){ + val cookie = new Cookie(name, value); + cookie.setPath(path); + if(maxAge>0){ + cookie.setMaxAge(maxAge); + } + return cookie; + } + } +} \ No newline at end of file diff --git a/src/main/java/de/hs_mannheim/informatik/ct/util/ScheduledMaintenanceTasks.java b/src/main/java/de/hs_mannheim/informatik/ct/util/ScheduledMaintenanceTasks.java index 5e63a05d..ef91b13a 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/util/ScheduledMaintenanceTasks.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/util/ScheduledMaintenanceTasks.java @@ -43,7 +43,7 @@ public class ScheduledMaintenanceTasks { private final int CRON_HOUR = 3; private final int CRON_MINUTE = 55; - private final String FORCED_END_TIME = "00:00:00"; + public static final String FORCED_END_TIME = "00:00:00"; //@Scheduled(fixedRate = 5 * 60 * 1000) // Every 5 Minutes @Scheduled(cron = "0 " + CRON_MINUTE + " " + CRON_HOUR + " * * *") // 3:55 AM diff --git a/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java b/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java new file mode 100644 index 00000000..4c31782f --- /dev/null +++ b/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java @@ -0,0 +1,51 @@ +package de.hs_mannheim.informatik.ct.web; + +/* + * Corona Tracking Tool der Hochschule Mannheim + * Copyright (C) 2021 Hochschule Mannheim + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import de.hs_mannheim.informatik.ct.controller.interceptor.CheckInInterceptor; +import de.hs_mannheim.informatik.ct.controller.resolver.CookieManagerResolver; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import java.util.List; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(checkInInterceptor()) + .addPathPatterns("/") + .addPathPatterns("/r/**"); + } + + @Override + public void addArgumentResolvers( + List resolvers) { + resolvers.add(new CookieManagerResolver()); + } + + @Bean + public CheckInInterceptor checkInInterceptor(){ + return new CheckInInterceptor(); + } +} \ No newline at end of file diff --git a/src/main/resources/static/general.css b/src/main/resources/static/general.css new file mode 100644 index 00000000..85a7d871 --- /dev/null +++ b/src/main/resources/static/general.css @@ -0,0 +1,40 @@ +.danger-color { + background: #f8d7da; + border-color: #d9534f !important; +} + +.custom-card { + display: flex; + flex-direction: column; + border: 2px solid #22376F; + border-radius: 3px; + margin: 5px; + padding: 5px; + background: #E9EBF1; +} + +.custom-card .custom-card-footer { + display: flex; + align-items: center; +} + +#check-in-alert-form{ + display: flex; + justify-content: space-between; + flex-wrap: wrap; +} + +.hs-button { + border: 2px solid #22376F; + border-radius: 3px; + background: #22376F; + color: #FFF; + padding: 5px; + margin: 0; +} + +.hs-button:hover { + background: #FFF; + color: #22376F; + cursor: pointer; +} \ No newline at end of file diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js new file mode 100644 index 00000000..381c0f27 --- /dev/null +++ b/src/main/resources/static/main.js @@ -0,0 +1,7 @@ +const checkInAlertForm = document.getElementById('check-in-alert-form') + +checkInAlertForm.onsubmit = e => { + if(!confirm("Wollen Sie sich wirklich auschecken?")){ + e.preventDefault(); + } +} \ No newline at end of file diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html index 12e3c393..365208a0 100644 --- a/src/main/resources/templates/layout.html +++ b/src/main/resources/templates/layout.html @@ -3,6 +3,7 @@ HSMA CTT + @@ -100,6 +101,7 @@
+ + +

Body contents

@@ -171,5 +181,7 @@ }); + + diff --git a/src/main/resources/templates/rooms/layout.html b/src/main/resources/templates/rooms/layout.html index 37dd01f7..02b8354c 100644 --- a/src/main/resources/templates/rooms/layout.html +++ b/src/main/resources/templates/rooms/layout.html @@ -4,8 +4,8 @@ HSMA CTT + - @@ -28,8 +28,17 @@

-
+ + + +
+
+ + diff --git a/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerOverrideTest.java b/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerOverrideTest.java index cbb410ed..9b363f0f 100644 --- a/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerOverrideTest.java +++ b/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerOverrideTest.java @@ -21,8 +21,7 @@ import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -103,7 +102,8 @@ public void checkInFullRoomWithOverride() throws Exception { .param("roomPin", TEST_ROOM_PIN) .with(csrf())) .andExpect(forwardedUrl(null)) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(cookie().value("checkedInEmail", TEST_USER_EMAIL)); } /** diff --git a/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerTest.java b/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerTest.java index b3ec2a3a..b7381dc5 100644 --- a/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerTest.java +++ b/src/test/java/de/hs_mannheim/informatik/ct/end_to_end/RoomControllerTest.java @@ -22,10 +22,7 @@ import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.net.URLDecoder; import java.net.URLEncoder; @@ -132,7 +129,8 @@ public void checkInEmptyRoom() throws Exception { .param("roomId", TEST_ROOM_NAME) .param("roomPin", TEST_ROOM_PIN) .with(csrf())) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(cookie().value("checkedInEmail", TEST_USER_EMAIL)); } @Test @@ -180,7 +178,8 @@ public void checkInFilledRoom() throws Exception { .param("roomId", TEST_ROOM_NAME) .param("roomPin", TEST_ROOM_PIN) .with(csrf())) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(cookie().value("checkedInEmail", TEST_USER_EMAIL)); } @Test @@ -233,6 +232,7 @@ public void checkOut() throws Exception { .param("roomPin", TEST_ROOM_PIN) .with(csrf())) .andExpect(status().isOk()) + .andExpect(cookie().value("checkedInEmail", TEST_USER_EMAIL)) .andDo( // check out result -> mockMvc.perform( @@ -241,6 +241,7 @@ public void checkOut() throws Exception { .param("visitorEmail", TEST_USER_EMAIL) .with(csrf())) .andExpect(status().isFound()) + .andExpect(cookie().value("checkedInEmail", "")) .andExpect(redirectedUrl("/r/checkedOut"))); } @@ -255,6 +256,7 @@ public void checkOutInvalidCredentials() throws Exception { .param("roomPin", TEST_ROOM_PIN) .with(csrf())) .andExpect(status().isOk()) + .andExpect(cookie().value("checkedInEmail", TEST_USER_EMAIL)) .andDo( // check out result -> mockMvc.perform( From 718e458f32bdd8ea5899bdca1136efae9bd986f0 Mon Sep 17 00:00:00 2001 From: "m.stock" <36995969+maxones25@users.noreply.github.com> Date: Thu, 18 Nov 2021 15:56:41 +0100 Subject: [PATCH 3/9] Change Text Alignment to center --- src/main/resources/templates/rooms/checkedIn.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/templates/rooms/checkedIn.html b/src/main/resources/templates/rooms/checkedIn.html index 5bc1c0c9..4404509a 100644 --- a/src/main/resources/templates/rooms/checkedIn.html +++ b/src/main/resources/templates/rooms/checkedIn.html @@ -15,21 +15,21 @@

Eingecheckt!

-

+

-

+

-
+

Bitte beim Verlassen des Raums auch an das - Abmelden denken. + Auschecken denken.

From f360759747c381f49fe1bef69bb22a05f8d43d57 Mon Sep 17 00:00:00 2001 From: "m.stock" <36995969+maxones25@users.noreply.github.com> Date: Thu, 18 Nov 2021 15:57:20 +0100 Subject: [PATCH 4/9] Move Check Cookie Code from Pre to Post Method --- .../informatik/ct/interceptor/CheckInInterceptor.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java b/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java index edf124c8..f6709091 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java @@ -26,7 +26,9 @@ import lombok.val; import lombok.var; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -47,7 +49,13 @@ public class CheckInInterceptor implements HandlerInterceptor { private static final String CHECKED_IN_COOKIE_NAME = "checkedInEmail"; @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + return true; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + @Nullable ModelAndView modelAndView) throws Exception { val cookieManager = new CookieManager(request, response); var isCheckedIn = false; val checkedInEmail = cookieManager.getCookieValue(CookieManager.Cookies.CHECKED_IN_EMAIL); @@ -62,7 +70,6 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons } request.setAttribute("checkedInEmail", checkedInEmail); request.setAttribute("isCheckedIn", isCheckedIn); - return true; } private String getCheckedInRoomName(String email){ From 47690cadb94609571c40595a8ee51bdf4c6ec7df Mon Sep 17 00:00:00 2001 From: 1826914 <1826914@stud.hs-mannheim.de> Date: Thu, 25 Nov 2021 13:21:39 +0100 Subject: [PATCH 5/9] added newlines, fixed package info and types in ContactTracingService --- src/main/java/de/hs_mannheim/informatik/ct/CtApp.java | 3 +++ .../de/hs_mannheim/informatik/ct/util/CookieManager.java | 8 ++++---- .../java/de/hs_mannheim/informatik/ct/web/WebConfig.java | 6 +++--- src/main/resources/static/general.css | 2 +- src/main/resources/static/main.js | 2 +- src/main/resources/templates/rooms/checkedIn.html | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java b/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java index de81ae6b..ae09065e 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java @@ -18,6 +18,9 @@ package de.hs_mannheim.informatik.ct; +import de.hs_mannheim.informatik.ct.model.Room; +import de.hs_mannheim.informatik.ct.persistence.repositories.RoomRepository; +import de.hs_mannheim.informatik.ct.persistence.services.RoomService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java index 831cdad4..6fe7f1f8 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java @@ -39,16 +39,16 @@ public CookieManager(HttpServletRequest request, HttpServletResponse response){ this.response = response; } - public static enum Cookies{ + public enum Cookies{ CHECKED_IN_EMAIL("checkedInEmail"); - private String name; + String name; - private Cookies(String name) { + Cookies(String name) { this.name = name; } - public String getName(){ + String getName(){ return this.name; } } diff --git a/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java b/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java index 4c31782f..e8400fa8 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/web/WebConfig.java @@ -1,5 +1,3 @@ -package de.hs_mannheim.informatik.ct.web; - /* * Corona Tracking Tool der Hochschule Mannheim * Copyright (C) 2021 Hochschule Mannheim @@ -18,6 +16,8 @@ * along with this program. If not, see . */ +package de.hs_mannheim.informatik.ct.web; + import de.hs_mannheim.informatik.ct.controller.interceptor.CheckInInterceptor; import de.hs_mannheim.informatik.ct.controller.resolver.CookieManagerResolver; import org.springframework.context.annotation.Bean; @@ -48,4 +48,4 @@ public void addArgumentResolvers( public CheckInInterceptor checkInInterceptor(){ return new CheckInInterceptor(); } -} \ No newline at end of file +} diff --git a/src/main/resources/static/general.css b/src/main/resources/static/general.css index 85a7d871..190af93e 100644 --- a/src/main/resources/static/general.css +++ b/src/main/resources/static/general.css @@ -37,4 +37,4 @@ background: #FFF; color: #22376F; cursor: pointer; -} \ No newline at end of file +} diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index 381c0f27..4c48c9c2 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -4,4 +4,4 @@ checkInAlertForm.onsubmit = e => { if(!confirm("Wollen Sie sich wirklich auschecken?")){ e.preventDefault(); } -} \ No newline at end of file +} diff --git a/src/main/resources/templates/rooms/checkedIn.html b/src/main/resources/templates/rooms/checkedIn.html index 5bc1c0c9..491aee77 100644 --- a/src/main/resources/templates/rooms/checkedIn.html +++ b/src/main/resources/templates/rooms/checkedIn.html @@ -36,4 +36,4 @@

- \ No newline at end of file + From d1767619ed0c6a913521e194d87b3383fd171ae6 Mon Sep 17 00:00:00 2001 From: 1826914 <1826914@stud.hs-mannheim.de> Date: Thu, 25 Nov 2021 13:26:28 +0100 Subject: [PATCH 6/9] eof newlines --- .../informatik/ct/interceptor/CheckInInterceptor.java | 2 +- .../java/de/hs_mannheim/informatik/ct/util/CookieManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java b/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java index f6709091..c9996129 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java @@ -87,4 +87,4 @@ private List findCurrentRoomVisitsByEmail(String email){ } return roomVisits; } -} \ No newline at end of file +} diff --git a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java index 6fe7f1f8..76982616 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java @@ -147,4 +147,4 @@ public Cookie build(){ return cookie; } } -} \ No newline at end of file +} From 428f125c650aaaeff6bb7359ef2d611a91ec1e0d Mon Sep 17 00:00:00 2001 From: 1826914 <1826914@stud.hs-mannheim.de> Date: Sun, 2 Jan 2022 14:49:37 +0100 Subject: [PATCH 7/9] organized imports formated some code --- .../java/de/hs_mannheim/informatik/ct/CtApp.java | 3 --- .../informatik/ct/controller/RoomController.java | 4 ++-- .../interceptor/CheckInInterceptor.java | 9 ++++----- .../controller/resolver/CookieManagerResolver.java | 13 ++++++------- .../informatik/ct/util/CookieManager.java | 9 +++++---- 5 files changed, 17 insertions(+), 21 deletions(-) rename src/main/java/de/hs_mannheim/informatik/ct/{ => controller}/interceptor/CheckInInterceptor.java (95%) diff --git a/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java b/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java index ae09065e..de81ae6b 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/CtApp.java @@ -18,9 +18,6 @@ package de.hs_mannheim.informatik.ct; -import de.hs_mannheim.informatik.ct.model.Room; -import de.hs_mannheim.informatik.ct.persistence.repositories.RoomRepository; -import de.hs_mannheim.informatik.ct.persistence.services.RoomService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java index 34c72dd8..2fc89da8 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/RoomController.java @@ -28,7 +28,6 @@ import java.nio.charset.StandardCharsets; import java.util.Optional; -import de.hs_mannheim.informatik.ct.util.CookieManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; @@ -47,6 +46,7 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; +import de.hs_mannheim.informatik.ct.util.CookieManager; import de.hs_mannheim.informatik.ct.controller.exception.InvalidRoomPinException; import de.hs_mannheim.informatik.ct.model.Room; import de.hs_mannheim.informatik.ct.model.RoomVisit; @@ -137,7 +137,7 @@ public String checkIn(@PathVariable String roomId, @PostMapping("/checkIn") @Transactional - public String checkIn(@ModelAttribute RoomVisit.Data visitData, Model model, CookieManager cookieManager) throws UnsupportedEncodingException, InvalidRoomPinException, InvalidEmailException, InvalidExternalUserdataException { + public String checkIn(@ModelAttribute RoomVisit.Data visitData, Model model, CookieManager cookieManager) throws UnsupportedEncodingException, InvalidRoomPinException, InvalidEmailException, InvalidExternalUserdataException { isRoomPinValidOrThrow(visitData); val room = roomService.getRoomOrThrow(visitData.getRoomId()); diff --git a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/interceptor/CheckInInterceptor.java similarity index 95% rename from src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java rename to src/main/java/de/hs_mannheim/informatik/ct/controller/interceptor/CheckInInterceptor.java index c9996129..c53e9d8e 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/interceptor/CheckInInterceptor.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/interceptor/CheckInInterceptor.java @@ -1,5 +1,3 @@ -package de.hs_mannheim.informatik.ct.controller.interceptor; - /* * Corona Tracking Tool der Hochschule Mannheim * Copyright (C) 2021 Hochschule Mannheim @@ -17,6 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +package de.hs_mannheim.informatik.ct.controller.interceptor; import de.hs_mannheim.informatik.ct.controller.Utilities; import de.hs_mannheim.informatik.ct.model.RoomVisit; @@ -59,9 +58,9 @@ public void postHandle(HttpServletRequest request, HttpServletResponse response, val cookieManager = new CookieManager(request, response); var isCheckedIn = false; val checkedInEmail = cookieManager.getCookieValue(CookieManager.Cookies.CHECKED_IN_EMAIL); - if(checkedInEmail!=null){ + if(checkedInEmail != null){ val checkedInRoom = getCheckedInRoomName(checkedInEmail); - if(checkedInRoom!=null){ + if(checkedInRoom != null){ isCheckedIn = true; request.setAttribute("checkedInRoom", checkedInRoom); }else{ @@ -74,7 +73,7 @@ public void postHandle(HttpServletRequest request, HttpServletResponse response, private String getCheckedInRoomName(String email){ List roomVisits = findCurrentRoomVisitsByEmail(email); - return roomVisits.size()>0 ? roomVisits.get(0).getRoom().getName() : null; + return roomVisits.size() > 0 ? roomVisits.get(0).getRoom().getName() : null; } private List findCurrentRoomVisitsByEmail(String email){ diff --git a/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java b/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java index 8fc8ca8e..df72095f 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/controller/resolver/CookieManagerResolver.java @@ -1,5 +1,3 @@ -package de.hs_mannheim.informatik.ct.controller.resolver; - /* * Corona Tracking Tool der Hochschule Mannheim * Copyright (C) 2021 Hochschule Mannheim @@ -17,19 +15,20 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +package de.hs_mannheim.informatik.ct.controller.resolver; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -import de.hs_mannheim.informatik.ct.util.CookieManager; import org.springframework.core.MethodParameter; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import de.hs_mannheim.informatik.ct.util.CookieManager; -public class CookieManagerResolver - implements HandlerMethodArgumentResolver { +public class CookieManagerResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter methodParameter) { diff --git a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java index 76982616..e61472e8 100644 --- a/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java +++ b/src/main/java/de/hs_mannheim/informatik/ct/util/CookieManager.java @@ -1,5 +1,3 @@ -package de.hs_mannheim.informatik.ct.util; - /* * Corona Tracking Tool der Hochschule Mannheim * Copyright (C) 2021 Hochschule Mannheim @@ -18,14 +16,17 @@ * along with this program. If not, see . */ -import lombok.val; -import org.springframework.web.util.WebUtils; +package de.hs_mannheim.informatik.ct.util; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.time.LocalTime; +import org.springframework.web.util.WebUtils; + +import lombok.val; + public class CookieManager { private HttpServletRequest request; private HttpServletResponse response; From 667233649f1da71dd379a875d795e39ef23057fd Mon Sep 17 00:00:00 2001 From: Oliver Hummel Date: Wed, 12 Jan 2022 22:29:28 +0100 Subject: [PATCH 8/9] Update layout.html Added a period at the end of the sentence. --- src/main/resources/templates/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html index c6296d1f..68a6cfb7 100644 --- a/src/main/resources/templates/layout.html +++ b/src/main/resources/templates/layout.html @@ -117,7 +117,7 @@ From 725dfc78e45b50e62a2d558ed11ec4ec6c2bb93a Mon Sep 17 00:00:00 2001 From: Oliver Hummel Date: Wed, 12 Jan 2022 22:33:26 +0100 Subject: [PATCH 9/9] Update layout.html Period added. --- src/main/resources/templates/rooms/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/rooms/layout.html b/src/main/resources/templates/rooms/layout.html index 02b8354c..4434650f 100644 --- a/src/main/resources/templates/rooms/layout.html +++ b/src/main/resources/templates/rooms/layout.html @@ -32,7 +32,7 @@