Skip to content
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
39 changes: 16 additions & 23 deletions JtProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,53 @@
</properties>
<dependencies>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>


<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>


<build>
<plugins>
<plugin>
Expand Down
22 changes: 22 additions & 0 deletions JtProject/src/main/java/DTO/AddToCartRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package DTO;

public class AddToCartRequest {
private int userId;
private int productId;

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public int getProductId() {
return productId;
}

public void setProductId(int productId) {
this.productId = productId;
}
}
31 changes: 31 additions & 0 deletions JtProject/src/main/java/DTO/DiscountPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package DTO;

public class DiscountPrice {
public int productid;
public int oldprice;
public int newprice;

public int getOldprice() {
return oldprice;
}

public void setOldprice(int oldprice) {
this.oldprice = oldprice;
}

public int getProductid() {
return productid;
}

public void setProductid(int productid) {
this.productid = productid;
}

public int getNewprice() {
return newprice;
}

public void setNewprice(int newprice) {
this.newprice = newprice;
}
}
13 changes: 13 additions & 0 deletions JtProject/src/main/java/DTO/OrderRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package DTO;

public class OrderRequest {
private long userId;

public long getUserId() {
return userId;
}

public void setUserId(long userId) {
this.userId = userId;
}
}
7 changes: 7 additions & 0 deletions JtProject/src/main/java/DTO/productdto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package DTO;

public class productdto {
public int id;
public int oldprice;
public int newprice;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import com.jtspringproject.JtSpringProject.models.User;
import com.jtspringproject.JtSpringProject.services.userService;
import com.jtspringproject.JtSpringProject.services.UserService;

@Configuration
public class SecurityConfiguration {

userService UserService;
UserService UserService;

public SecurityConfiguration(userService UserService) {
public SecurityConfiguration(UserService UserService) {
this.UserService = UserService;
}

Expand All @@ -32,6 +32,7 @@ SecurityFilterChain adminFilterChain(HttpSecurity http) throws Exception {
http.antMatcher("/admin/**")
.authorizeHttpRequests(requests -> requests
.requestMatchers(new AntPathRequestMatcher("/admin/login")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/admin/setprice")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/admin/**")).hasRole("ADMIN")
)
.formLogin(login -> login
Expand Down Expand Up @@ -62,7 +63,7 @@ public static class UserConfigurationAdapter{
@Bean
SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(requests -> requests
.antMatchers("/login", "/register", "/newuserregister" ,"/test", "/test2").permitAll()
.antMatchers("/login", "/register", "/newuserregister" ,"/test", "/test2","/products","/allusers","/searchproducts","/logs","/Placeorder","/addtocart","/getallcarts","/newuser","/allorders","/Discounts").permitAll()
.antMatchers("/**").hasRole("USER"))
.formLogin(login -> login
.loginPage("/login")
Expand Down Expand Up @@ -97,15 +98,11 @@ UserDetailsService userDetailsService() {

return org.springframework.security.core.userdetails.User
.withUsername(username)
.passwordEncoder(input->passwordEncoder().encode(input))
.password(user.getPassword())
.roles(role)
.build();
};
}

@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,52 @@
import java.sql.ResultSet;
import java.util.List;

import DTO.productdto;
import com.jtspringproject.JtSpringProject.models.Logs;
import com.jtspringproject.JtSpringProject.services.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import com.jtspringproject.JtSpringProject.models.Category;
import com.jtspringproject.JtSpringProject.models.Product;
import com.jtspringproject.JtSpringProject.models.User;
import com.jtspringproject.JtSpringProject.services.categoryService;
import com.jtspringproject.JtSpringProject.services.productService;
import com.jtspringproject.JtSpringProject.services.userService;
import com.jtspringproject.JtSpringProject.services.CategoryService;
import com.jtspringproject.JtSpringProject.services.ProductService;
import com.jtspringproject.JtSpringProject.services.UserService;

@Controller
@RequestMapping("/admin")
public class AdminController {

private final userService userService;
private final categoryService categoryService;
private final productService productService;
private final UserService userService;
private final CategoryService categoryService;
private final ProductService productService;
private final LogService logservice;

@Autowired
public AdminController(userService userService, categoryService categoryService, productService productService) {
public AdminController(UserService userService, CategoryService categoryService, ProductService productService, LogService logservice) {
this.userService = userService;
this.categoryService = categoryService;
this.productService = productService;
this.logservice= logservice;
}

@GetMapping("/logs")
public List<Logs> getalllogs(){
return logservice.getalllogs();
}

@PostMapping("/setprice")
@ResponseBody
public void setprice( @RequestBody productdto product){
this.productService.updateProductPrice(product.id,product);
}

@GetMapping("/index")
public String index(Model model) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
Expand Down Expand Up @@ -250,4 +260,5 @@ public String updateUserProfile(@RequestParam("userid") int userid,@RequestParam
return "redirect:index";
}


}
Loading
Loading