Clean Shopping Cart on Logout for real
This commit is contained in:
parent
a2aca7a8ca
commit
577a4f72f0
|
@ -1,13 +1,11 @@
|
||||||
package org.hso.ecommerce.controller;
|
package org.hso.ecommerce.controller;
|
||||||
|
|
||||||
|
import org.hso.ecommerce.entities.shop.ShoppingCart;
|
||||||
import org.hso.ecommerce.entities.user.User;
|
import org.hso.ecommerce.entities.user.User;
|
||||||
import org.hso.ecommerce.repos.user.UserRepository;
|
import org.hso.ecommerce.repos.user.UserRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -61,9 +59,9 @@ public class LoginController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("logout")
|
@PostMapping("logout")
|
||||||
public String logoutPost(HttpServletResponse response, HttpSession session) {
|
public String logoutPost(@RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart, HttpSession session) {
|
||||||
session.removeAttribute("userId");
|
session.removeAttribute("userId");
|
||||||
session.removeAttribute("shoppingCart");
|
shoppingCart.clear();
|
||||||
|
|
||||||
return "redirect:/";
|
return "redirect:/";
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue