Commit dcd3b615 authored by keita.onoguchi's avatar keita.onoguchi

Merge branch 'カート機能' into 'master'

カート機能途中

See merge request !28
parents c5a4e8fc 1c0b08d9
package com.example;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
public void configure(WebSecurity web) throws Exception{
web.debug(false).ignoring().antMatchers("/images/**", "/js/**", "/css/**", "/fonts/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.mvcMatchers("/limited/login","/limited/signUp").permitAll() //ログイン前でもアクセス可能なURLの指定
.mvcMatchers("/limited/admin/**").hasRole("ADMIN")//ADMIN権限のユーザーのみアクセスできるURLの指定
.anyRequest().authenticated()//ログイン前は他のアドレスにログインできないよう指定s
.and()
.formLogin()
.loginProcessingUrl("/login") //ログイン処理でpostするURL
.loginPage("/limited/login") //ログインページのURL
.defaultSuccessUrl("/limited/top", true) //ログイン成功時のURL
.usernameParameter("email").passwordParameter("password") //ログインのパラメーター指定
.and()
.logout()
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID") //ログアウト時キャッシュを削除する処理
.logoutSuccessUrl("/limited/login"); //ログアウト後に表示するURL
}
@Bean //パスワードのハッシュか
PasswordEncoder passwordEncoder(){
return new Pbkdf2PasswordEncoder();
}
}
//package com.example;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.builders.WebSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
//
//
//@EnableWebSecurity
//public class SecurityConfig extends WebSecurityConfigurerAdapter{
//
// @Override
// public void configure(WebSecurity web) throws Exception{
// web.debug(false).ignoring().antMatchers("/images/**", "/js/**", "/css/**", "/fonts/**");
// }
//
// @Override
// protected void configure(HttpSecurity http) throws Exception {
// http
// .authorizeRequests()
// .mvcMatchers("/limited/login","/limited/signUp").permitAll() //ログイン前でもアクセス可能なURLの指定
// .mvcMatchers("/limited/admin/**").hasRole("ADMIN")//ADMIN権限のユーザーのみアクセスできるURLの指定
// .anyRequest().authenticated()//ログイン前は他のアドレスにログインできないよう指定s
// .and()
// .formLogin()
// .loginProcessingUrl("/login") //ログイン処理でpostするURL
// .loginPage("/limited/login") //ログインページのURL
// .defaultSuccessUrl("/limited/top", true) //ログイン成功時のURL
// .usernameParameter("email").passwordParameter("password") //ログインのパラメーター指定
// .and()
// .logout()
// .invalidateHttpSession(true)
// .deleteCookies("JSESSIONID") //ログアウト時キャッシュを削除する処理
// .logoutSuccessUrl("/limited/login"); //ログアウト後に表示するURL
// }
//
// @Bean //パスワードのハッシュか
// PasswordEncoder passwordEncoder(){
// return new Pbkdf2PasswordEncoder();
// }
//}
......@@ -2,6 +2,7 @@ package com.example.api;
import java.sql.Date;
import java.time.LocalDate;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
......@@ -10,24 +11,24 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.example.domain.SessionData;
import com.example.domain.Cart;
import com.example.domain.CartData;
import com.example.domain.User;
import com.example.service.LoginUserDetailsService;
@RestController
@RequestMapping("limited")
@SessionAttributes(value = {"sessionData"})
@SessionAttributes(names ="cart")
public class EcsiteRestController {
@Autowired
LoginUserDetailsService loginUserDetailsService;
@ModelAttribute(value = "sessionData") // (1)
public SessionData sessionData() {
return new SessionData();
@ModelAttribute("cart") // (1)
public ArrayList<Cart> setSessionData(ArrayList<Cart> arrayList) {
return arrayList;
}
@PostMapping("signUp")
......@@ -43,9 +44,10 @@ public class EcsiteRestController {
}
@PostMapping("inputCart")
public void inputCart(@RequestParam SessionData data, Model model) {
data.setSesionData(data.getShoesId(), data.getQuantity());
model.addAttribute("cart", data.getCart());
public void inputCart(@RequestBody CartData data, Model model, Cart cart) {
System.out.print(data.getShoesId());
cart.setCart(data.getShoesId(), data.getQuantity());
//return cart.getCart();
}
}
\ No newline at end of file
......@@ -13,26 +13,29 @@ import com.example.service.ShoesService;
import lombok.Getter;
import lombok.Setter;
@Component
@Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Setter
//@Component
//@Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Getter
public class SessionData implements Serializable{
@Setter
public class Cart /*implements Serializable*/{
/**
*
*/
private static final long serialVersionUID = 1L;
//private static final long serialVersionUID = 1L;
@Autowired
ShoesService shoesService;
private Integer shoesId;
private String photo;
private String shoesName;
private Integer shoesSize;
private Integer quantity;
private Integer price;
private Integer productStatus;
public void setSesionData(Integer shoesId, Integer quantity) {
public void setCart(Integer shoesId, Integer quantity) {
System.out.println(shoesId);
Shoes shoes = new Shoes();
shoes = shoesService.findOne(shoesId);
this.shoesId = shoesId;
......@@ -41,11 +44,12 @@ public class SessionData implements Serializable{
this.shoesSize = shoes.getSize();
this.quantity = quantity;
this.price = shoes.getPrice() * quantity;
System.out.print(this.price);
}
public ArrayList<SessionData> getCart(){
ArrayList<SessionData> cartList = new ArrayList<SessionData>();
SessionData data = new SessionData();
public ArrayList<Cart> getCart(){
ArrayList<Cart> cartList = new ArrayList<Cart>();
Cart data = new Cart();
data.getShoesId();
data.getPhoto();
data.getShoesName();
......@@ -54,6 +58,5 @@ public class SessionData implements Serializable{
data.getPrice();
cartList.add(data);
return cartList;
}
}
\ No newline at end of file
package com.example.domain;
import org.springframework.stereotype.Component;
import lombok.Getter;
import lombok.Setter;
@Component
@Setter
@Getter
public class CartData{
private Integer shoesId;
private Integer quantity;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment