Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
shopping-mall
Commits
beb4a801
Commit
beb4a801
authored
Jan 11, 2021
by
박상호
🎼
Browse files
12453d
parents
e7be03bb
42ab4e72
Changes
16
Show whitespace changes
Inline
Side-by-side
client/src/App.js
View file @
beb4a801
...
@@ -38,6 +38,12 @@ function App() {
...
@@ -38,6 +38,12 @@ function App() {
<
Route
path
=
"
/payment
"
component
=
{
Payment
}
/
>
<
Route
path
=
"
/payment
"
component
=
{
Payment
}
/
>
<
Route
path
=
"
/mypage
"
component
=
{
Mypage
}
/
>
<
Route
path
=
"
/mypage
"
component
=
{
Mypage
}
/
>
<
Route
path
=
'
/kakao
'
component
=
{()
=>
{
window
.
location
.
href
=
'
https://compmath.korea.ac.kr
'
;
return
null
;
}}
/
>
<
Route
path
=
'
/kakao
'
component
=
{()
=>
{
window
.
location
.
href
=
'
https://compmath.korea.ac.kr
'
;
return
null
;
}}
/
>
<
PrivateRoute
path
=
"
/profile
"
>
<
Profile
/>
<
/PrivateRoute
>
<
PrivateRoute
path
=
"
/profile-edit
"
>
<
EditProfile
/>
<
/PrivateRoute
>
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
/Switch
>
<
/Switch
>
<
/Router
>
<
/Router
>
...
...
client/src/AuthRoute.js
deleted
100644 → 0
View file @
e7be03bb
import
React
from
'
react
'
import
{
Route
,
Redirect
}
from
"
react-router-dom
"
function
AuthRoute
({})
\ No newline at end of file
client/src/Pages/Login.js
View file @
beb4a801
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
{
Form
,
Col
,
Container
,
Button
,
Row
}
from
'
react-bootstrap
'
;
import
{
Form
,
Col
,
Container
,
Button
,
Row
}
from
'
react-bootstrap
'
;
...
@@ -63,6 +63,7 @@ function Login() {
...
@@ -63,6 +63,7 @@ function Login() {
<
/Container
>
<
/Container
>
<
/div
>
<
/div
>
)
)
}
}
export
default
Login
export
default
Login
\ No newline at end of file
client/src/Pages/Logout.js
0 → 100644
View file @
beb4a801
// import { Button } from 'bootstrap'
// import React from 'react'
// import { handleLogout } from '../utils/auth'
// function logout() {
// return (
// <div>
// <Button onClick={()=>handleLogout()}>Logout</Button>
// </div>
// )
// }
// export default logout
client/src/Pages/PrivateRoute.js
0 → 100644
View file @
beb4a801
import
React
from
'
react
'
import
{
Redirect
,
Route
}
from
'
react-router-dom
'
import
{
isAuthenticated
}
from
'
../utils/auth
'
function
PrivateRoute
({
path
,
children
})
{
if
(
isAuthenticated
())
{
return
(
<
Route
path
=
{
path
}
>
{
children
}
<
/Route
>
)
}
else
{
return
(
<
Redirect
to
=
"
/login
"
/>
)
}
}
export
default
PrivateRoute
client/src/Pages/Signup.js
View file @
beb4a801
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
{
Redirect
}
from
'
react-router-dom
'
;
import
axios
from
'
axios
'
import
Nav1
from
'
../Components/MainNav
'
;
import
Nav2
from
'
../Components/SubNav
'
;
import
{
Form
,
Col
,
Container
,
Button
,
Row
,
Alert
}
from
'
react-bootstrap
'
import
{
Form
,
Col
,
Container
,
Button
,
Row
,
Alert
}
from
'
react-bootstrap
'
import
axios
from
'
axio
s
'
;
import
catchErrors
from
'
../utils/catchError
s
'
const
INIT_USER
=
{
const
INIT_USER
=
{
name
:
''
,
name
:
''
,
...
@@ -14,20 +16,15 @@ const INIT_USER = {
...
@@ -14,20 +16,15 @@ const INIT_USER = {
function
Signup
()
{
function
Signup
()
{
const
[
user
,
setUser
]
=
useState
(
true
)
const
[
user
,
setUser
]
=
useState
(
true
)
//const [disabled, setDisabled] = useState(true)
const
[
error
,
setError
]
=
useState
(
''
)
const
[
error
,
setError
]
=
useState
(
''
)
//useEffect(() => {
const
[
validated
,
setValidated
]
=
useState
(
false
);
// const isUser = Object.values(user).every(el => Boolean(el))
// isUser ? setDisabled(false) : setDisabled(true)
//}, user)
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
const
{
name
,
value
}
=
event
.
target
setUser
({
...
user
,
[
name
]:
value
})
setUser
({
...
user
,
[
name
]:
value
})
}
}
const
[
validated
,
setValidated
]
=
useState
(
false
);
async
function
handleSubmit
(
event
)
{
async
function
handleSubmit
(
event
)
{
event
.
preventDefault
()
event
.
preventDefault
()
...
@@ -42,31 +39,41 @@ function Signup() {
...
@@ -42,31 +39,41 @@ function Signup() {
try
{
try
{
setError
(
''
)
setError
(
''
)
// const response = await axios.post('/api/user/signup', user)
const
response
=
await
axios
.
post
(
'
/api/users/signup
'
,
user
)
const
response
=
await
fetch
(
'
/api/users/signup
'
,
{
console
.
log
(
response
.
data
)
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
user
)
})
const
data
=
await
response
.
json
()
console
.
log
(
data
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
catchErrors
(
error
,
setError
)
setError
(
'
다시 시도하세요.
'
)
}
}
}
function
checkPassword
(
event
){
const
p1
=
user
.
password
const
p2
=
user
.
password2
if
(
p1
!==
p2
){
event
.
preventDefault
();
event
.
stopPropagation
();
alert
(
'
비밀번호가 일치하지 않습니다.
'
)
return
false
}
else
{
return
true
}
}
}
return
(
return
(
<
div
>
<
div
>
<
Container
className
=
"
my-5
"
>
<
Container
className
=
"
my-5
"
>
{
error
&&
<
Alert
variant
=
'
danger
'
>
{
error
}
<
/Alert>
}
<
Row
className
=
"
justify-content-center
"
>
<
Row
className
=
"
justify-content-center
"
>
<
Col
md
=
{
6
}
xs
=
{
10
}
className
=
"
border
"
style
=
{{
background
:
'
#F7F3F3
'
}}
>
<
Col
md
=
{
6
}
xs
=
{
10
}
className
=
"
border
"
style
=
{{
background
:
'
#F7F3F3
'
}}
>
<
h2
className
=
"
text-center mt-5
"
>
Sign
Up
<
/h2
>
<
h2
className
=
"
text-center mt-5
"
>
Sign
Up
<
/h2
>
{
error
&&
<
Alert
variant
=
'
danger
'
>
{
error
}
<
/Alert>
}
<
Form
<
Form
noValidate
validated
=
{
validated
}
noValidate
validated
=
{
validated
}
onSubmit
=
{
handleSubmit
}
onSubmit
=
{
handleSubmit
}
...
@@ -134,7 +141,8 @@ function Signup() {
...
@@ -134,7 +141,8 @@ function Signup() {
style
=
{{
width
:
'
160px
'
}}
style
=
{{
width
:
'
160px
'
}}
value
=
{
user
.
password
}
value
=
{
user
.
password
}
required
required
onChange
=
{
handleChange
}
/
>
onChange
=
{
handleChange
}
/
>
<
Form
.
Control
.
Feedback
className
=
"
text-center
"
type
=
"
invalid
"
>
<
Form
.
Control
.
Feedback
className
=
"
text-center
"
type
=
"
invalid
"
>
비밀번호를
입력하세요
.
비밀번호를
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Control.Feedback
>
...
@@ -150,7 +158,8 @@ function Signup() {
...
@@ -150,7 +158,8 @@ function Signup() {
style
=
{{
width
:
'
160px
'
}}
style
=
{{
width
:
'
160px
'
}}
value
=
{
user
.
password2
}
value
=
{
user
.
password2
}
required
required
onChange
=
{
handleChange
}
/
>
onChange
=
{
handleChange
}
/
>
<
Form
.
Control
.
Feedback
type
=
"
invalid
"
>
비밀번호를
한번
더
입력하세요
.
<
Form
.
Control
.
Feedback
type
=
"
invalid
"
>
비밀번호를
한번
더
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Control.Feedback
>
<
/Form.Row
>
<
/Form.Row
>
...
@@ -169,7 +178,9 @@ function Signup() {
...
@@ -169,7 +178,9 @@ function Signup() {
<
/Form.Row
>
<
/Form.Row
>
<
/Form.Group
>
<
/Form.Group
>
<
Button
<
Button
style
=
{{
background
:
'
#91877F
'
,
borderColor
:
'
#91877F
'
}}
type
=
"
submit
"
block
>
style
=
{{
background
:
'
#91877F
'
,
borderColor
:
'
#91877F
'
}}
type
=
"
submit
"
block
onClick
=
{
checkPassword
}
>
Sign
Up
Sign
Up
<
/Button
>
<
/Button
>
<
/Form
>
<
/Form
>
...
...
client/src/utils/Auth.js
View file @
beb4a801
const
users
=
[
import
axios
from
"
axios
"
{
id
:
'
wodus
'
,
password
:
'
123
'
},
{
id
:
'
kim
'
,
password
:
'
456
'
},
]
export
function
signIn
({
id
,
password
}){
export
function
handleLogin
(){
const
user
=
users
.
find
(
user
=>
user
.
id
===
id
&&
user
.
password
===
password
);
localStorage
.
setItem
(
'
loginStatus
'
,
'
true
'
)
if
(
user
===
undefined
)
throw
new
Error
();
return
user
;
}
}
export
function
isAuthenticated
(){
export
async
function
handleLogout
(){
const
userId
=
localStorage
.
getItem
(
"
loginStatus
"
)
localStorage
.
removeItem
(
'
loginStatus
'
)
if
(
userId
)
{
await
axios
.
get
(
'
/api/auth/logout
'
)
return
userId
}
else
{
return
false
}
}
}
\ No newline at end of file
client/src/utils/catchErrors.js
View file @
beb4a801
<<<<<<<
HEAD
// import React from 'react'
// import React from 'react'
function
catchErrors
(
error
,
displayError
)
{
function
catchErrors
(
error
,
displayError
)
{
...
@@ -19,3 +20,22 @@ function catchErrors(error, displayError) {
...
@@ -19,3 +20,22 @@ function catchErrors(error, displayError) {
}
}
export
default
catchErrors
export
default
catchErrors
=======
function
catchErrors
(
error
,
displayError
){
let
errorMsg
if
(
error
.
response
){
errorMsg
=
error
.
response
.
data
console
.
log
(
errorMsg
)
}
else
if
(
error
.
request
){
errorMsg
=
error
.
request
console
.
log
(
errorMsg
)
}
else
{
errorMsg
=
error
.
message
console
.
log
(
errorMsg
)
}
displayError
(
errorMsg
)
}
export
default
catchErrors
>>>>>>>
origin
/
jaeyeon
server/app.js
View file @
beb4a801
...
@@ -7,6 +7,7 @@ import cartRouter from './routes/cart.routes.js';
...
@@ -7,6 +7,7 @@ import cartRouter from './routes/cart.routes.js';
import
path
from
'
path
'
import
path
from
'
path
'
import
kakaopayRoutes
from
'
./routes/kakaopay.routes.js
'
import
kakaopayRoutes
from
'
./routes/kakaopay.routes.js
'
import
config
from
'
./config.js
'
import
config
from
'
./config.js
'
import
authRouter
from
'
./routes/auth.routes.js
'
import
cors
from
'
cors
'
import
cors
from
'
cors
'
connectDb
()
connectDb
()
...
@@ -24,6 +25,7 @@ app.use(express.static(path.join(process.cwd(), 'dist')))
...
@@ -24,6 +25,7 @@ app.use(express.static(path.join(process.cwd(), 'dist')))
// app.use('/', indexRouter);
// app.use('/', indexRouter);
app
.
use
(
'
/
'
,
kakaopayRoutes
)
app
.
use
(
'
/
'
,
kakaopayRoutes
)
app
.
use
(
'
/api/users
'
,
userRouter
)
app
.
use
(
'
/api/users
'
,
userRouter
)
app
.
use
(
'
/api/auth
'
,
authRouter
)
app
.
use
(
'
/api/product
'
,
productRouter
)
app
.
use
(
'
/api/product
'
,
productRouter
)
app
.
use
(
'
/api/addcart
'
,
cartRouter
)
app
.
use
(
'
/api/addcart
'
,
cartRouter
)
...
...
server/config.js
View file @
beb4a801
...
@@ -3,7 +3,8 @@ const config = {
...
@@ -3,7 +3,8 @@ const config = {
port
:
process
.
env
.
PORT
||
3001
,
port
:
process
.
env
.
PORT
||
3001
,
jwtSecret
:
process
.
env
.
JWT_SECRET
||
'
My_Secret_Key
'
,
jwtSecret
:
process
.
env
.
JWT_SECRET
||
'
My_Secret_Key
'
,
mongoDbUri
:
process
.
env
.
MONGEDB_URI
||
'
mongodb://localhost/shopping-mall
'
,
mongoDbUri
:
process
.
env
.
MONGEDB_URI
||
'
mongodb://localhost/shopping-mall
'
,
kakaoAdminKey
:
'
b2dda7685c5b2990684d813e362cff07
'
kakaoAdminKey
:
'
b2dda7685c5b2990684d813e362cff07
'
,
cookieMaxAge
:
60
*
60
*
24
*
7
*
1000
}
}
// const config = {
// const config = {
...
...
server/controllers/auth.controller.js
0 → 100644
View file @
beb4a801
import
User
from
'
../schemas/User.js
'
import
bcrypt
from
'
bcryptjs
'
import
jwt
from
'
jsonwebtoken
'
import
config
from
'
../config.js
'
const
login
=
async
(
req
,
res
)
=>
{
const
{
id
,
password
}
=
req
.
body
console
.
log
(
id
,
password
)
try
{
const
user
=
await
User
.
findOne
({
id
}).
select
(
'
+password
'
)
if
(
!
user
){
return
res
.
status
(
404
).
send
(
`
${
id
}
가 존재하지 않습니다.`
)
}
const
passwordMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
)
if
(
passwordMatch
){
const
token
=
jwt
.
sign
({
userId
:
user
.
_id
},
config
.
jwtSecret
,{
expiresIn
:
'
3d
'
})
res
.
cookie
(
'
token
'
,
token
,{
maxAge
:
config
.
cookieMaxAge
,
httpOnly
:
true
,
secure
:
config
.
env
===
'
production
'
})
res
.
send
(
'
로그인 되었습니다.
'
)
}
else
{
res
.
status
(
401
).
send
(
'
비밀번호가 일치하지 않습니다.
'
)
}
}
catch
(
error
){
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
로그인 실패. 다시 시도하세요.
'
)
}
}
// const logout =(req,res)=>{
// res.clearCookie('token')
// res.send('로그아웃 되었습니다.')
// }
export
default
{
login
}
\ No newline at end of file
server/controllers/user.controller.js
View file @
beb4a801
...
@@ -11,37 +11,33 @@ const profileUpload = upload.fields([ //.single 한개, .fileds 여러개
...
@@ -11,37 +11,33 @@ const profileUpload = upload.fields([ //.single 한개, .fileds 여러개
const
signup
=
async
(
req
,
res
)
=>
{
const
signup
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
console
.
log
(
req
.
body
)
console
.
log
(
'
req.body.name=
'
,
req
.
body
.
name
)
const
{
name
,
number1
,
number2
,
id
,
password
,
tel
}
=
req
.
body
const
{
name
,
number1
,
number2
,
id
,
password
,
password2
,
tel
}
=
req
.
body
try
{
try
{
if
(
!
isLength
(
password
,
{
min
:
8
,
max
:
15
}))
{
if
(
!
isLength
(
password
,
{
min
:
8
,
max
:
15
})){
return
res
.
status
(
422
).
json
({
message
:
'
비밀번호는 8-15자리로 입력해주세요.
'
}
)
return
res
.
status
(
422
).
send
(
'
비밀번호는 8-15자리로 입력해주세요.
'
)
}
}
// if (!isLength(name, { min: 3, max: 10 })) {
const
user
=
await
User
.
findOne
({
id
})
// return res.status(422).send('이름은 3-10자로 입력해주세요.')
if
(
user
){
// } else if (!isLength(password, { min: 8, max: 15 })){
return
res
.
status
(
422
).
send
(
`
${
id
}
가 이미 사용중입니다.`
)
// return res.status(422).json({message: '비밀번호는 8-15자리로 입력해주세요.'})
}
// }
// const user = await User.findOne({id})
// if (user) {
const
hash
=
await
bcrypt
.
hash
(
password
,
10
)
// return res.status(422).send(`${id}가 이미 사용중입니다.`)
// }
const
newUser
=
await
new
User
({
const
hash
=
await
bcrypt
.
hash
(
password
,
10
)
const
newUser
=
await
new
User
({
name
,
name
,
number1
,
number1
,
number2
,
number2
,
id
,
id
,
password
:
hash
,
password
:
hash
,
password2
,
tel
,
tel
}).
save
()
}).
save
()
console
.
log
(
newUser
)
console
.
log
(
newUser
)
res
.
json
(
newUser
)
res
.
json
(
newUser
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
res
.
status
(
500
).
json
({
message
:
'
죄송합니다. 다시 입력해 주십시오.
'
}
)
res
.
status
(
500
).
send
(
'
죄송합니다. 다시 입력해 주십시오.
'
)
}
}
}
}
...
...
server/package.json
View file @
beb4a801
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"bcryptjs"
:
"^2.4.3"
,
"bcryptjs"
:
"^2.4.3"
,
"cors"
:
"^2.8.5"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.17.1"
,
"express"
:
"^4.17.1"
,
"jsonwebtoken"
:
"^8.5.1"
,
"mongoose"
:
"^5.11.9"
,
"mongoose"
:
"^5.11.9"
,
"multer"
:
"^1.4.2"
,
"multer"
:
"^1.4.2"
,
"node-fetch"
:
"^2.6.1"
,
"node-fetch"
:
"^2.6.1"
,
...
...
server/routes/auth.routes.js
0 → 100644
View file @
beb4a801
import
express
from
"
express
"
;
import
authCtrl
from
'
../controllers/auth.controller.js
'
;
const
router
=
express
.
Router
()
router
.
route
(
'
/login
'
)
.
post
(
authCtrl
.
login
)
// router.route('/logout')
// .get(authCtrl.logout)
export
default
router
\ No newline at end of file
server/schemas/Product.js
View file @
beb4a801
import
mongoose
from
'
mongoose
'
import
mongoose
from
'
mongoose
'
const
{
String
,
Number
,
Array
}
=
mongoose
.
Schema
.
Types
const
{
String
}
=
mongoose
.
Schema
.
Types
const
ProductSchema
=
new
mongoose
.
Schema
({
const
ProductSchema
=
new
mongoose
.
Schema
({
pro_name
:
{
pro_name
:
{
...
...
server/schemas/User.js
View file @
beb4a801
import
mongoose
from
'
mongoose
'
import
mongoose
from
"
mongoose
"
;
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
}
=
mongoose
.
Schema
.
Types
...
@@ -10,35 +10,30 @@ const UserSchema = new mongoose.Schema({
...
@@ -10,35 +10,30 @@ const UserSchema = new mongoose.Schema({
id
:
{
id
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
unique
:
true
unique
:
true
,
},
},
password
:
{
password
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
select
:
false
},
},
confirm_password
:{
type
:
String
,
number1
:
{
required
:
true
,
select
:
false
},
phoneNumber
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
role
:
{
number2
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
},
},
birth
:
{
tel
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
sex
:
{
role
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
}
}
},
{
},
{
timestamps
:
true
timestamps
:
true
...
...
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