diff --git a/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java b/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java index b830db94..6a54b317 100644 --- a/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java @@ -68,8 +68,8 @@ public String getPass(Ticket ticket) throws TicketPassFailedException { } Product product = ticket.getProduct(); - EventTicketClass newClass = this.createClass(product); - EventTicketObject newObject = this.createObject(ticket); + EventTicketClass ticketClass = this.createClass(product); + EventTicketObject ticketObject = this.createObject(ticket); HashMap claims = new HashMap(); claims.put("iss", credentials.getClientEmail()); @@ -79,8 +79,8 @@ public String getPass(Ticket ticket) throws TicketPassFailedException { claims.put("iat", Instant.now().getEpochSecond()); HashMap payload = new HashMap(); - payload.put("eventTicketClasses", List.of(newClass)); - payload.put("eventTicketObjects", List.of(newObject)); + payload.put("eventTicketClasses", List.of(ticketClass)); + payload.put("eventTicketObjects", List.of(ticketObject)); claims.put("payload", payload); Algorithm algorithm = Algorithm.RSA256( diff --git a/src/main/java/ch/wisv/events/webshop/controller/WebshopPassesController.java b/src/main/java/ch/wisv/events/webshop/controller/WebshopPassesController.java new file mode 100644 index 00000000..ee03058d --- /dev/null +++ b/src/main/java/ch/wisv/events/webshop/controller/WebshopPassesController.java @@ -0,0 +1,91 @@ +package ch.wisv.events.webshop.controller; + +import ch.wisv.events.core.exception.normal.TicketNotFoundException; +import ch.wisv.events.core.exception.normal.TicketPassFailedException; +import ch.wisv.events.core.model.customer.Customer; +import ch.wisv.events.core.model.ticket.Ticket; +import ch.wisv.events.core.service.auth.AuthenticationService; +import ch.wisv.events.core.service.order.OrderService; +import ch.wisv.events.core.service.ticket.TicketService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Controller +@RequestMapping("/passes") +public class WebshopPassesController extends WebshopController { + /** TicketService. */ + private final TicketService ticketService; + + /** + * @param authenticationService of type AuthenticationService + * @param orderService of type OrderService + * @param ticketService of type TicketService + */ + public WebshopPassesController( + AuthenticationService authenticationService, + OrderService orderService, + TicketService ticketService + ) { + super(orderService, authenticationService); + this.ticketService = ticketService; + } + + /** + * Get wallet pass of ticket. + */ + @GetMapping("/apple/{key}/wallet.pkpass") + public void getApplePass(HttpServletResponse response, @PathVariable String key) throws IOException { + Customer customer = authenticationService.getCurrentCustomer(); + + try { + Ticket ticket = ticketService.getByKey(key); + + if (!ticket.owner.equals(customer) && ticket.owner.isVerifiedChMember()) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return; + } + + byte[] bytes = ticketService.getApplePass(ticket); + + response.setContentType("application/vnd.apple.pkpass"); + response.setContentLength(bytes.length); + response.getOutputStream().write(bytes); + response.getOutputStream().close(); + } + catch (TicketNotFoundException e) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + catch (TicketPassFailedException | IOException e) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + + /** + * Redirect the user to the Google Pass URL. + */ + @GetMapping("/google/{key}") + public void getGooglePass(HttpServletResponse response, @PathVariable String key) throws IOException { + Customer customer = authenticationService.getCurrentCustomer(); + + try { + Ticket ticket = ticketService.getByKey(key); + + if (!ticket.owner.equals(customer) && ticket.owner.isVerifiedChMember()) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return; + } + + String link = ticketService.getGooglePass(ticket); + response.sendRedirect(link); + } + catch (TicketNotFoundException e) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + catch (TicketPassFailedException | IOException e) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } +} diff --git a/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java b/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java index 7fb118c2..99ce9846 100644 --- a/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java +++ b/src/main/java/ch/wisv/events/webshop/controller/WebshopTicketController.java @@ -3,7 +3,6 @@ import ch.wisv.events.core.exception.normal.CustomerNotFoundException; import ch.wisv.events.core.exception.normal.TicketNotFoundException; import ch.wisv.events.core.exception.normal.TicketNotTransferableException; -import ch.wisv.events.core.exception.normal.TicketPassFailedException; import ch.wisv.events.core.model.customer.Customer; import ch.wisv.events.core.model.ticket.Ticket; import ch.wisv.events.core.service.auth.AuthenticationService; @@ -169,58 +168,4 @@ public void getQrCode(HttpServletResponse response, @PathVariable String key) th response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } - - /** - * Get wallet pass of ticket. - */ - @GetMapping("/{key}/wallet.pkpass") - public void getApplePass(HttpServletResponse response, @PathVariable String key) throws IOException { - Customer customer = authenticationService.getCurrentCustomer(); - try { - Ticket ticket = ticketService.getByKey(key); - - if (!ticket.owner.equals(customer)) { - response.sendError(HttpServletResponse.SC_FORBIDDEN); - return; - } - - byte[] bytes = ticketService.getApplePass(ticket); - - response.setContentType("application/vnd.apple.pkpass"); - response.setContentLength(bytes.length); - response.getOutputStream().write(bytes); - response.getOutputStream().close(); - } - catch (TicketNotFoundException e) { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } - catch (TicketPassFailedException | IOException e) { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } - } - - /** - * Redirect the user to the Google Pass URL. - */ - @GetMapping("/{key}/googlewallet") - public void getGooglePass(HttpServletResponse response, @PathVariable String key) throws IOException { - Customer customer = authenticationService.getCurrentCustomer(); - try { - Ticket ticket = ticketService.getByKey(key); - - if (!ticket.owner.equals(customer)) { - response.sendError(HttpServletResponse.SC_FORBIDDEN); - return; - } - - String link = ticketService.getGooglePass(ticket); - response.sendRedirect(link); - } - catch (TicketNotFoundException e) { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } - catch (TicketPassFailedException | IOException e) { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } - } } diff --git a/src/main/resources/templates/mail/order.html b/src/main/resources/templates/mail/order.html index 3dbefbeb..dbaf3bd8 100644 --- a/src/main/resources/templates/mail/order.html +++ b/src/main/resources/templates/mail/order.html @@ -325,14 +325,14 @@

Ticket overview

style="font-family: Arial, sans-serif;color: #5e5e5e;font-size: 16px;text-align: left;border-collapse: collapse;background-color: #f3f3f3;padding: 5px; text-align: center;" > Add to Apple Wallet diff --git a/src/main/resources/templates/webshop/overview/index.html b/src/main/resources/templates/webshop/overview/index.html index 5802d0b3..63740871 100644 --- a/src/main/resources/templates/webshop/overview/index.html +++ b/src/main/resources/templates/webshop/overview/index.html @@ -217,11 +217,11 @@
Open tickets