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")
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/")

View File

@ -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