Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user home #54

Open
wants to merge 1 commit into
base: master2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class UserController{
@Autowired
private productService productService;

@Autowired
private cartService cartService;

@GetMapping("/register")
public String registerUser()
{
Expand All @@ -56,22 +59,19 @@ public String userlogin(Model model) {

return "userLogin";
}
@RequestMapping(value = "userloginvalidate", method = RequestMethod.POST)
public ModelAndView userlogin( @RequestParam("username") String username, @RequestParam("password") String pass,Model model,HttpServletResponse res) {

System.out.println(pass);
User u = this.userService.checkLogin(username, pass);
System.out.println(u.getUsername());
if(u.getUsername().equals(username)) {

res.addCookie(new Cookie("username", u.getUsername()));
ModelAndView mView = new ModelAndView("index");
mView.addObject("user", u);
List<Product> products = this.productService.getProducts();

@RequestMapping(value = "loginvalidate", method = RequestMethod.POST)
public ModelAndView userlogin( @RequestParam("username") String username, @RequestParam("password") String pass) {
User user = this.userService.checkLogin(username, pass);
System.out.println(user.getUsername());
if(user.getUsername().equals(username)) {
ModelAndView mView = new ModelAndView("userHome");
mView.addObject("user", user);
List<Product> products = this.productService.getProducts();
if (products.isEmpty()) {
mView.addObject("msg", "No products are available");
} else {
System.out.println(products.get(0).getName());
mView.addObject("products", products);
}
return mView;
Expand All @@ -81,9 +81,16 @@ public ModelAndView userlogin( @RequestParam("username") String username, @Reque
mView.addObject("msg", "Please enter correct email and password");
return mView;
}

}


// @GetMapping("/{userId}/carts")
// public String viewCart(@PathVariable String username, Model model) {
// Cart cart = cartService.getCartByUsername(username);
// model.addAttribute("cart", cart);
// return "cart";
// }


@GetMapping("/user/products")
public ModelAndView getproduct() {
Expand Down
88 changes: 88 additions & 0 deletions JtProject/src/main/webapp/views/userHome.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>User Panel</title>

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<!-- Font Awesome CSS -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css"
integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
</head>

<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<%-- <img src="../static/images/logo.png" width="auto" height="40" class="d-inline-block align-top" alt="Logo"/>--%>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="/cartproduct">Cart</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/">Logout</a>
</li>
</ul>
</div>
</div>
</nav>

<!-- Jumbotron -->
<div class="jumbotron text-center">
<h1 class="display-4">Welcome ${user.username}</h1>
<hr class="my-4">
</div>


<!-- Container for Cards -->
<div class="container-fluid">

<div class="row">
<c:forEach var="product" items="${products}">
<div class="col-sm-3 pt-4">
<div class="card" style="background-color: white;">
<div class="card-body text-center">
<h4 class="card-title">${product.name}</h4>
<img src="${product.image}" alt="${product.name}" height="150px" width="150px">
<p class="card-text">Description: ${product.description}</p>
<p class="card-text">Price: $${product.price}</p>
<p class="card-text">Quantity: ${product.quantity}</p>
<p class="card-text">Weight: ${product.weight} lbs</p>
<a href="/admin/products/${product.id}/edit" class="card-link btn btn-primary"> + Add </a>
</div>
</div>
</div>
</c:forEach>
</div>

</div>

<!-- Bootstrap JS and Popper.js -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
</body>

</html>