Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
dcd3b615
Commit
dcd3b615
authored
Oct 19, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'カート機能' into 'master'
カート機能途中 See merge request
!28
parents
c5a4e8fc
1c0b08d9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
64 deletions
+84
-64
SecurityConfig.java
src/main/java/com/example/SecurityConfig.java
+44
-44
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+12
-9
Cart.java
src/main/java/com/example/domain/Cart.java
+13
-11
CartData.java
src/main/java/com/example/domain/CartData.java
+15
-0
No files found.
src/main/java/com/example/SecurityConfig.java
View file @
dcd3b615
package
com
.
example
;
//
package com.example;
//
import
org.springframework.context.annotation.Bean
;
//
import org.springframework.context.annotation.Bean;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
//
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.builders.WebSecurity;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
//
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
//
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import
org.springframework.security.crypto.password.PasswordEncoder
;
//
import org.springframework.security.crypto.password.PasswordEncoder;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
//
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
//
//
@EnableWebSecurity
//
@EnableWebSecurity
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
//
public class SecurityConfig extends WebSecurityConfigurerAdapter{
//
@Override
//
@Override
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
//
public void configure(WebSecurity web) throws Exception{
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
,
"/fonts/**"
);
//
web.debug(false).ignoring().antMatchers("/images/**", "/js/**", "/css/**", "/fonts/**");
}
//
}
//
@Override
//
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
//
protected void configure(HttpSecurity http) throws Exception {
http
//
http
.
authorizeRequests
()
//
.authorizeRequests()
.
mvcMatchers
(
"/limited/login"
,
"/limited/signUp"
).
permitAll
()
//ログイン前でもアクセス可能なURLの指定
//
.mvcMatchers("/limited/login","/limited/signUp").permitAll() //ログイン前でもアクセス可能なURLの指定
.
mvcMatchers
(
"/limited/admin/**"
).
hasRole
(
"ADMIN"
)
//ADMIN権限のユーザーのみアクセスできるURLの指定
//
.mvcMatchers("/limited/admin/**").hasRole("ADMIN")//ADMIN権限のユーザーのみアクセスできるURLの指定
.
anyRequest
().
authenticated
()
//ログイン前は他のアドレスにログインできないよう指定s
//
.anyRequest().authenticated()//ログイン前は他のアドレスにログインできないよう指定s
.
and
()
//
.and()
.
formLogin
()
//
.formLogin()
.
loginProcessingUrl
(
"/login"
)
//ログイン処理でpostするURL
//
.loginProcessingUrl("/login") //ログイン処理でpostするURL
.
loginPage
(
"/limited/login"
)
//ログインページのURL
//
.loginPage("/limited/login") //ログインページのURL
.
defaultSuccessUrl
(
"/limited/top"
,
true
)
//ログイン成功時のURL
//
.defaultSuccessUrl("/limited/top", true) //ログイン成功時のURL
.
usernameParameter
(
"email"
).
passwordParameter
(
"password"
)
//ログインのパラメーター指定
//
.usernameParameter("email").passwordParameter("password") //ログインのパラメーター指定
.
and
()
//
.and()
.
logout
()
//
.logout()
.
invalidateHttpSession
(
true
)
//
.invalidateHttpSession(true)
.
deleteCookies
(
"JSESSIONID"
)
//ログアウト時キャッシュを削除する処理
//
.deleteCookies("JSESSIONID") //ログアウト時キャッシュを削除する処理
.
logoutSuccessUrl
(
"/limited/login"
);
//ログアウト後に表示するURL
//
.logoutSuccessUrl("/limited/login"); //ログアウト後に表示するURL
}
//
}
//
@Bean
//パスワードのハッシュか
//
@Bean //パスワードのハッシュか
PasswordEncoder
passwordEncoder
(){
//
PasswordEncoder passwordEncoder(){
return
new
Pbkdf2PasswordEncoder
();
//
return new Pbkdf2PasswordEncoder();
}
//
}
}
//
}
src/main/java/com/example/api/EcsiteRestController.java
View file @
dcd3b615
...
@@ -2,6 +2,7 @@ package com.example.api;
...
@@ -2,6 +2,7 @@ package com.example.api;
import
java.sql.Date
;
import
java.sql.Date
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
...
@@ -10,24 +11,24 @@ import org.springframework.web.bind.annotation.ModelAttribute;
...
@@ -10,24 +11,24 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
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.RestController
;
import
org.springframework.web.bind.annotation.SessionAttributes
;
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.domain.User
;
import
com.example.service.LoginUserDetailsService
;
import
com.example.service.LoginUserDetailsService
;
@RestController
@RestController
@RequestMapping
(
"limited"
)
@RequestMapping
(
"limited"
)
@SessionAttributes
(
value
=
{
"sessionData"
}
)
@SessionAttributes
(
names
=
"cart"
)
public
class
EcsiteRestController
{
public
class
EcsiteRestController
{
@Autowired
@Autowired
LoginUserDetailsService
loginUserDetailsService
;
LoginUserDetailsService
loginUserDetailsService
;
@ModelAttribute
(
value
=
"sessionData
"
)
// (1)
@ModelAttribute
(
"cart
"
)
// (1)
public
SessionData
sessionData
(
)
{
public
ArrayList
<
Cart
>
setSessionData
(
ArrayList
<
Cart
>
arrayList
)
{
return
new
SessionData
()
;
return
arrayList
;
}
}
@PostMapping
(
"signUp"
)
@PostMapping
(
"signUp"
)
...
@@ -43,9 +44,10 @@ public class EcsiteRestController {
...
@@ -43,9 +44,10 @@ public class EcsiteRestController {
}
}
@PostMapping
(
"inputCart"
)
@PostMapping
(
"inputCart"
)
public
void
inputCart
(
@RequestParam
SessionData
data
,
Model
model
)
{
public
void
inputCart
(
@RequestBody
CartData
data
,
Model
model
,
Cart
cart
)
{
data
.
setSesionData
(
data
.
getShoesId
(),
data
.
getQuantity
());
System
.
out
.
print
(
data
.
getShoesId
());
model
.
addAttribute
(
"cart"
,
data
.
getCart
());
cart
.
setCart
(
data
.
getShoesId
(),
data
.
getQuantity
());
//return cart.getCart();
}
}
}
}
\ No newline at end of file
src/main/java/com/example/domain/
SessionData
.java
→
src/main/java/com/example/domain/
Cart
.java
View file @
dcd3b615
...
@@ -13,26 +13,29 @@ import com.example.service.ShoesService;
...
@@ -13,26 +13,29 @@ import com.example.service.ShoesService;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
@Component
//@Component
@Scope
(
value
=
"session"
,
proxyMode
=
ScopedProxyMode
.
TARGET_CLASS
)
//@Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Setter
@Getter
@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
@Autowired
ShoesService
shoesService
;
ShoesService
shoesService
;
private
Integer
shoesId
;
private
Integer
shoesId
;
private
String
photo
;
private
String
photo
;
private
String
shoesName
;
private
String
shoesName
;
private
Integer
shoesSize
;
private
Integer
shoesSize
;
private
Integer
quantity
;
private
Integer
quantity
;
private
Integer
price
;
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
shoes
=
new
Shoes
();
shoes
=
shoesService
.
findOne
(
shoesId
);
shoes
=
shoesService
.
findOne
(
shoesId
);
this
.
shoesId
=
shoesId
;
this
.
shoesId
=
shoesId
;
...
@@ -41,11 +44,12 @@ public class SessionData implements Serializable{
...
@@ -41,11 +44,12 @@ public class SessionData implements Serializable{
this
.
shoesSize
=
shoes
.
getSize
();
this
.
shoesSize
=
shoes
.
getSize
();
this
.
quantity
=
quantity
;
this
.
quantity
=
quantity
;
this
.
price
=
shoes
.
getPrice
()
*
quantity
;
this
.
price
=
shoes
.
getPrice
()
*
quantity
;
System
.
out
.
print
(
this
.
price
);
}
}
public
ArrayList
<
SessionData
>
getCart
(){
public
ArrayList
<
Cart
>
getCart
(){
ArrayList
<
SessionData
>
cartList
=
new
ArrayList
<
SessionData
>();
ArrayList
<
Cart
>
cartList
=
new
ArrayList
<
Cart
>();
SessionData
data
=
new
SessionData
();
Cart
data
=
new
Cart
();
data
.
getShoesId
();
data
.
getShoesId
();
data
.
getPhoto
();
data
.
getPhoto
();
data
.
getShoesName
();
data
.
getShoesName
();
...
@@ -54,6 +58,5 @@ public class SessionData implements Serializable{
...
@@ -54,6 +58,5 @@ public class SessionData implements Serializable{
data
.
getPrice
();
data
.
getPrice
();
cartList
.
add
(
data
);
cartList
.
add
(
data
);
return
cartList
;
return
cartList
;
}
}
}
}
\ No newline at end of file
src/main/java/com/example/domain/CartData.java
0 → 100644
View file @
dcd3b615
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment