diff --git a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java index 7eab0c6..af1f387 100644 --- a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java +++ b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java @@ -31,9 +31,14 @@ public class RequestController { } @PostMapping("/login") - public String loginPost(HttpServletResponse response) { - response.addCookie(new Cookie("login", "true")); - return "redirect:/"; + public String loginPost(HttpServletResponse response, @RequestParam(value = "goto", required = false) String gto) { + response.addCookie(new Cookie("login", "true")); + + if (gto != null && gto.startsWith("/")) { + return "redirect:" + gto; + } else { + return "redirect:/"; + } } @PostMapping("/logout") @@ -77,8 +82,12 @@ public class RequestController { } @PostMapping("/shop/articles/{id}") - public String shopArticlesByIdBuy(HttpServletResponse response) { - return "redirect:/shop/checkout"; + public String shopArticlesByIdBuy(@RequestAttribute("customer") Boolean isCustomer, @PathVariable("id") Integer id) { + if (isCustomer) { + return "redirect:/shop/checkout"; + } else { + return "redirect:/login?goto=%2Fshop%2Farticles%2F"+id; + } } @GetMapping("/user/") diff --git a/prototype/src/main/java/org/hso/ecommerce/components/LoginIntercepter.java b/prototype/src/main/java/org/hso/ecommerce/components/LoginIntercepter.java index 42a5924..91d186b 100644 --- a/prototype/src/main/java/org/hso/ecommerce/components/LoginIntercepter.java +++ b/prototype/src/main/java/org/hso/ecommerce/components/LoginIntercepter.java @@ -21,10 +21,11 @@ public class LoginIntercepter implements HandlerInterceptor { for (Cookie c : cookies) { if (c.getName().equals("login")) { request.setAttribute("customer", c.getValue().equals("true")); + return true; } } } - + request.setAttribute("customer", false); return true; } @Override