fix flow for loggedout checkout

This commit is contained in:
CodeSteak 2020-01-26 13:47:54 +01:00
parent f53a442fa6
commit b25a9842e4
2 changed files with 16 additions and 5 deletions

View File

@ -29,9 +29,16 @@ 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:/";
System.out.println(gto);
if (gto != null && gto.startsWith("/")) {
return "redirect:" + gto;
} else {
return "redirect:/";
}
} }
@PostMapping("/logout") @PostMapping("/logout")
@ -75,8 +82,12 @@ public class RequestController {
} }
@PostMapping("/shop/articles/{id}") @PostMapping("/shop/articles/{id}")
public String shopArticlesByIdBuy() { 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

@ -10,7 +10,7 @@
<body> <body>
<!-- <nav th:replace="/fragments/header :: header">Header</nav> --> <!-- <nav th:replace="/fragments/header :: header">Header</nav> -->
<main class="content-width modal"> <main class="content-width modal">
<form class="detailgrid s hero " method="post" th:action="@{/login}"> <form class="detailgrid s hero " method="post">
<div class="s"> <div class="s">
<label for="username">Email Adresse</label> <label for="username">Email Adresse</label>
<input class="full-width" type="text" name="username" placeholder="Email Adresse" id="username" required> <input class="full-width" type="text" name="username" placeholder="Email Adresse" id="username" required>