Merge pull request 'Clean Shopping Cart on Logout' (#123) from feature/clean_shopping_on_logout into master
Reviewed-on: #123 Reviewed-by: Jannik Seiler <seil0@mosad.xyz>
This commit is contained in:
commit
758c6810ab
|
@ -1,19 +1,16 @@
|
|||
package org.hso.ecommerce.controller;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.hso.ecommerce.entities.shop.ShoppingCart;
|
||||
import org.hso.ecommerce.entities.user.User;
|
||||
import org.hso.ecommerce.repos.user.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
|
@ -62,8 +59,10 @@ public class LoginController {
|
|||
}
|
||||
|
||||
@PostMapping("logout")
|
||||
public String logoutPost(HttpServletResponse response, HttpSession session) {
|
||||
public String logoutPost(@RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart, HttpSession session) {
|
||||
session.removeAttribute("userId");
|
||||
shoppingCart.clear();
|
||||
|
||||
return "redirect:/";
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue