reimplement "fix flow for loggedout checkout" ( b25a9842e4 )

This commit is contained in:
CodeSteak 2020-02-11 23:36:34 +01:00
parent 02deef4ad7
commit c756469f05
2 changed files with 16 additions and 6 deletions

View File

@ -31,9 +31,14 @@ public class RequestController {
} }
@PostMapping("/login") @PostMapping("/login")
public String loginPost(HttpServletResponse response) { public String loginPost(HttpServletResponse response, @RequestParam(value = "goto", required = false) String gto) {
response.addCookie(new Cookie("login", "true")); response.addCookie(new Cookie("login", "true"));
return "redirect:/";
if (gto != null && gto.startsWith("/")) {
return "redirect:" + gto;
} else {
return "redirect:/";
}
} }
@PostMapping("/logout") @PostMapping("/logout")
@ -77,8 +82,12 @@ public class RequestController {
} }
@PostMapping("/shop/articles/{id}") @PostMapping("/shop/articles/{id}")
public String shopArticlesByIdBuy(HttpServletResponse response) { public String shopArticlesByIdBuy(@RequestAttribute("customer") Boolean isCustomer, @PathVariable("id") Integer id) {
return "redirect:/shop/checkout"; if (isCustomer) {
return "redirect:/shop/checkout";
} else {
return "redirect:/login?goto=%2Fshop%2Farticles%2F"+id;
}
} }
@GetMapping("/user/") @GetMapping("/user/")

View File

@ -21,10 +21,11 @@ public class LoginIntercepter implements HandlerInterceptor {
for (Cookie c : cookies) { for (Cookie c : cookies) {
if (c.getName().equals("login")) { if (c.getName().equals("login")) {
request.setAttribute("customer", c.getValue().equals("true")); request.setAttribute("customer", c.getValue().equals("true"));
return true;
} }
} }
} }
request.setAttribute("customer", false);
return true; return true;
} }
@Override @Override