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
reservation-service
Commits
f10c71ec
Commit
f10c71ec
authored
Oct 09, 2020
by
Ha YeaJin
Browse files
채린 merge
parents
60447e84
1a1b300b
Changes
17
Hide whitespace changes
Inline
Side-by-side
server/app.js
View file @
f10c71ec
...
...
@@ -7,6 +7,7 @@ const logger = require('morgan');
const
indexRouter
=
require
(
'
./routes/index
'
);
const
usersRouter
=
require
(
'
./routes/users
'
);
const
loginRouter
=
require
(
'
./routes/login
'
);
const
reserveRouter
=
require
(
'
./routes/reserves
'
);
const
connect
=
require
(
'
./schemas
'
);
const
app
=
express
();
...
...
@@ -31,7 +32,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app
.
use
(
'
/
'
,
indexRouter
);
app
.
use
(
'
/users
'
,
usersRouter
);
app
.
use
(
'
/login
'
,
loginRouter
);
app
.
use
(
'
/reserves
'
,
reserveRouter
);
// catch 404 and forward to error handler
app
.
use
(
function
(
req
,
res
,
next
)
{
...
...
server/client/package.json
View file @
f10c71ec
...
...
@@ -11,6 +11,7 @@
"bootstrap"
:
"^4.5.2"
,
"formik"
:
"^2.1.5"
,
"jquery"
:
"^3.5.1"
,
"mongoose"
:
"^5.10.6"
,
"popper.js"
:
"^1.16.1"
,
"react"
:
"^16.13.1"
,
"react-dom"
:
"^16.13.1"
,
...
...
server/client/src/Components/List.js
0 → 100644
View file @
f10c71ec
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
{
Field
,
Formik
}
from
'
formik
'
;
import
axios
from
'
axios
'
;
import
{
render
}
from
'
react-dom
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
styled
from
'
styled-components
'
;
function
List
(
props
)
{
function
remove
()
{
console
.
log
(
props
.
_id
)
axios
.
delete
(
`/reserves/
${
props
.
_id
}
`
,
{
data
:
{
_id
:
props
.
_id
,
}})
.
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
신청이 완료되었습니다!
"
)
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
};
return
(
<
div
>
<
div
>
날짜
:
{
props
.
date
}
<
/div
>
<
div
>
이름
:
{
props
.
name
}
<
/div
>
<
div
>
강의실
:
{
props
.
room
}
<
/div
>
<
div
>
시간
:
{
props
.
time
}
<
/div
>
<
div
>
사용인원
:
{
props
.
num
}
<
/div
>
<
div
>
{
props
.
_id
}
<
/div
>
<
form
onSubmit
=
{
remove
}
className
=
"
col-sm-3
"
>
<
button
type
=
"
submit
"
className
=
"
btn btn-dark
"
>
신청
취소
<
/button
>
<
/form
>
<
/div
>
)
}
export
default
List
;
\ No newline at end of file
server/client/src/Components/Menu.js
View file @
f10c71ec
...
...
@@ -13,12 +13,13 @@ const Nav = styled.nav`
function
Menu
()
{
const
[
state
,
setState
]
=
useState
()
const
name
=
localStorage
.
getItem
(
'
name
'
);
if
(
state
)
return
<
Redirect
to
=
"
/
"
/>
;
function
logout
()
{
localStorage
.
removeItem
(
'
token
'
);
alert
(
"
로그
인 화면으로 이동합
니다.
"
);
localStorage
.
clear
(
);
alert
(
"
로그
아웃 되었습
니다.
"
);
setState
(
true
);
}
...
...
@@ -40,11 +41,15 @@ function Menu() {
<
Link
to
=
"
/apply
"
className
=
"
nav-link
"
>
대관
신청
<
/Link
>
<
/li
>
<
li
className
=
"
nav-item
"
>
<
Link
to
=
"
/check
"
className
=
"
nav-link
"
>
대관
확인
/
취소
<
/Link
>
<
Link
to
=
{{
pathname
:
`/check/
${
localStorage
.
getItem
(
'
_id
'
)}
`
,
state
:
{
id
:
localStorage
.
getItem
(
'
_id
'
)
},
}}
className
=
"
nav-link
"
>
대관
확인
/
취소
<
/Link
>
<
/li
>
<
/ul
>
<
div
>
<
div
><
/div
>
<
div
>
{
name
}
님
안녕하세요
.
<
/div
>
<
button
onClick
=
{
logout
}
type
=
"
button
"
>
로그아웃
<
/button
>
<
/div
>
<
/div
>
...
...
server/client/src/Pages/ApplyPage.js
View file @
f10c71ec
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
{
Formik
}
from
'
formik
'
;
import
Menu
from
'
../Components/Menu
'
;
import
axios
from
'
axios
'
;
function
Apply
()
{
return
(
<
div
>
<
Menu
/>
<
div
className
=
"
container
"
>
apply
<
Formik
initialValues
=
{{
date
:
"
20201003
"
,
time
:
"
시간
"
,
room
:
"
9-116
"
,
name
:
"
종윤
"
,
_id
:
"
5f6fa20001988e5604603870
"
,
reason
:
"
study hard
"
,
member
:
"
jinju rkyoung
"
,
approve
:
false
,
num
:
5
,
}}
onSubmit
=
{(
values
,
{
setSubmitting
})
=>
{
axios
({
method
:
'
post
'
,
url
:
'
/reserves
'
,
data
:
values
,
}).
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
신청이 완료되었습니다!
"
)
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
setTimeout
(()
=>
{
setSubmitting
(
false
);
},
400
);
// finish the cycle in handler
}}
>
{({
handleSubmit
,
isSubmitting
,
})
=>
(
<
div
className
=
"
row justify-content-center align-items-center
"
>
<
form
onSubmit
=
{
handleSubmit
}
className
=
"
col-sm-3
"
>
<
button
type
=
"
submit
"
className
=
"
btn btn-dark
"
disabled
=
{
isSubmitting
}
>
Sign
Up
<
/button
>
<
/form
>
<
/div
>
)}
<
/Formik
>
<
/div
>
<
/div
>
)
...
...
server/client/src/Pages/ChangePage.js
0 → 100644
View file @
f10c71ec
import
React
,
{
useState
}
from
'
react
'
;
import
{
Formik
}
from
'
formik
'
;
import
*
as
Yup
from
'
yup
'
;
import
axios
from
'
axios
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
function
Change
(
props
)
{
const
[
state
,
setState
]
=
useState
();
if
(
state
)
{
return
<
Redirect
to
=
"
/
"
/>
;
}
console
.
log
(
props
)
return
(
<
div
className
=
"
d-flex flex-column justify-content-between vh-100
"
>
<
Formik
initialValues
=
{{
password
:
''
}}
validationSchema
=
{
Yup
.
object
({
password
:
Yup
.
string
()
.
required
(
'
비밀번호를 입력해주세요.
'
)
.
min
(
8
,
'
8자 이상 입력해주세요.
'
),
password2
:
Yup
.
string
()
.
required
(
'
비밀번호를 다시 입력해주세요.
'
)
.
min
(
8
,
'
8자 이상 입력해주세요.
'
)
.
oneOf
([
Yup
.
ref
(
"
password
"
),
null
],
'
비밀번호가 일치하지 않습니다.
'
),
})}
onSubmit
=
{(
values
,
{
setSubmitting
})
=>
{
axios
.
put
(
`/users/change/
${
props
.
location
.
state
.
id
}
`
,
{
...
values
},
)
.
then
(
res
=>
{
console
.
log
(
res
.
data
);
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
회원정보가 수정되었습니다!
"
)
setState
(
true
);
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
setTimeout
(()
=>
{
setSubmitting
(
false
);
},
400
);
// finish the cycle in handler
}}
>
{({
errors
,
touched
,
handleSubmit
,
getFieldProps
,
// contain values, handleChange, handleBlur
isSubmitting
,
})
=>
(
<
div
className
=
"
row justify-content-center align-items-center
"
>
<
form
onSubmit
=
{
handleSubmit
}
className
=
"
col-sm-3
"
>
<
div
className
=
"
form-group mb-4
"
>
<
input
className
=
{(
touched
.
password
&&
errors
.
password
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
password
"
name
=
"
password
"
{...
getFieldProps
(
'
password
'
)}
placeholder
=
"
새 비밀번호를 입력해주세요.
"
/>
{
touched
.
password
&&
errors
.
password
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
password
}
<
/ div
>
)
:
null
}
<
/div
>
<
div
className
=
"
form-group mb-4
"
>
<
input
className
=
{(
touched
.
password2
&&
errors
.
password2
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
password
"
name
=
"
password2
"
{...
getFieldProps
(
'
password2
'
)}
placeholder
=
"
새 비밀번호를 다시 입력해주세요.
"
/>
{
touched
.
password2
&&
errors
.
password2
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
password2
}
<
/div
>
)
:
null
}
<
/div
>
<
button
type
=
"
submit
"
className
=
"
btn btn-light
"
disabled
=
{
isSubmitting
}
>
저장
<
/button
>
<
/form
>
<
/div
>
)}
<
/Formik
>
<
/div
>
);
}
export
default
Change
;
server/client/src/Pages/CheckPage.js
View file @
f10c71ec
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
Menu
from
'
../Components/Menu
'
;
import
List
from
'
../Components/List
'
;
import
axios
from
'
axios
'
;
function
Check
()
{
function
Check
(
props
)
{
function
getReserve
()
{
axios
.
get
(
`/reserves/
${
props
.
match
.
params
.
id
}
`
,
{
headers
:
{
authorization
:
localStorage
.
getItem
(
'
token
'
)
},
})
.
then
(
res
=>
{
if
(
res
.
status
!==
201
)
{
alert
(
res
.
data
.
error
);
}
console
.
log
(
res
.
data
);
setReserve
(
res
.
data
);
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
}
const
[
reserve
,
setReserve
]
=
useState
([]);
useEffect
(()
=>
{
getReserve
();
},
[])
return
(
<
div
>
<
Menu
/>
<
div
className
=
"
container
"
>
check
{
reserve
.
map
((
reserve
,
index
)
=>
<
List
id
=
{
props
.
match
.
params
.
id
}
index
=
{
index
}
date
=
{
reserve
.
date
}
name
=
{
reserve
.
name
}
room
=
{
reserve
.
room
}
time
=
{
reserve
.
time
}
num
=
{
reserve
.
num
}
_id
=
{
reserve
.
_id
}
/
>
)}
<
/div
>
<
/div
>
)
...
...
server/client/src/Pages/FindPage.js
0 → 100644
View file @
f10c71ec
import
React
,
{
useState
}
from
'
react
'
;
import
{
Field
,
Formik
}
from
'
formik
'
;
import
*
as
Yup
from
'
yup
'
;
import
axios
from
'
axios
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
function
Find
()
{
const
[
state
,
setState
]
=
useState
();
if
(
state
)
{
return
<
Redirect
to
=
{{
pathname
:
`/change/
${
localStorage
.
getItem
(
'
_id
'
)}
`
,
state
:
{
id
:
localStorage
.
getItem
(
'
_id
'
)
},
}}
/>
;
}
return
(
<
div
className
=
"
d-flex flex-column justify-content-between vh-100
"
>
<
Formik
initialValues
=
{{
id
:
''
,
question
:
''
,
answer
:
''
}}
validationSchema
=
{
Yup
.
object
({
id
:
Yup
.
string
()
.
required
(
'
학번을 입력해주세요.
'
),
answer
:
Yup
.
string
()
.
required
(
'
답변을 입력해주세요.
'
),
})}
onSubmit
=
{(
values
,
{
setSubmitting
})
=>
{
axios
({
method
:
'
post
'
,
url
:
'
/login/find
'
,
data
:
values
,
}).
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
localStorage
.
setItem
(
'
_id
'
,
res
.
data
.
users
.
_id
)
setState
(
true
);
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
console
.
log
(
values
);
setTimeout
(()
=>
{
setSubmitting
(
false
);
},
400
);
// finish the cycle in handler
}}
>
{({
errors
,
touched
,
handleSubmit
,
getFieldProps
,
// contain values, handleChange, handleBlur
isSubmitting
,
})
=>
(
<
div
className
=
"
row justify-content-center align-items-center
"
>
<
form
onSubmit
=
{
handleSubmit
}
className
=
"
col-sm-3
"
>
<
div
className
=
"
form-group mb-4
"
>
<
input
className
=
{(
touched
.
id
&&
errors
.
id
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
number
"
name
=
"
id
"
{...
getFieldProps
(
'
id
'
)}
placeholder
=
"
Input Student Id
"
/>
{
touched
.
id
&&
errors
.
id
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
id
}
<
/div
>
)
:
null
}
<
/div
>
<
div
className
=
"
form-group mb-4
"
>
<
label
>
본인
확인
질문
<
/label
>
<
Field
as
=
"
select
"
name
=
"
question
"
>
<
option
value
=
""
>
질문을
선택하세요
<
/option
>
<
option
value
=
"
life
"
>
자신의
인생
좌우명은
?
<
/option
>
<
option
value
=
"
school
"
>
자신이
다녔던
초등학교의
이름은
?
<
/option
>
<
option
value
=
"
place
"
>
기억에
남는
추억의
장소는
?
<
/option
>
<
/Field
>
<
/div
>
<
div
className
=
"
form-group mb-4
"
>
<
input
className
=
{(
touched
.
answer
&&
errors
.
answer
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
text
"
name
=
"
answer
"
{...
getFieldProps
(
'
answer
'
)}
placeholder
=
"
Input answer
"
/>
{
touched
.
answer
&&
errors
.
answer
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
answer
}
<
/div
>
)
:
null
}
<
/div
>
<
button
type
=
"
submit
"
className
=
"
btn btn-dark
"
disabled
=
{
isSubmitting
}
>
submit
<
/button
>
<
button
><
Link
to
=
"
/login
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/
"
>
홈
<
/Link></
button
>
<
/form
>
<
/div
>
)}
<
/Formik
>
<
/div
>
);
}
export
default
Find
;
server/client/src/Pages/HomePage.js
View file @
f10c71ec
...
...
@@ -10,6 +10,10 @@ function Home() {
home
<
button
><
Link
to
=
"
/login
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/signup
"
>
회원가입
<
/Link></
button
>
<
button
><
Link
to
=
{{
pathname
:
`/change/
${
localStorage
.
getItem
(
'
_id
'
)}
`
,
state
:
{
id
:
localStorage
.
getItem
(
'
_id
'
)
},
}}
>
비밀번호
수정
<
/Link></
button
>
<
/div
>
<
/div
>
)
...
...
server/client/src/Pages/LoginPage.js
View file @
f10c71ec
...
...
@@ -171,11 +171,14 @@ function Login() {
/>
<
/div
>
<
/div
>
<
button
type
=
"
submit
"
className
=
{
"
btn btn-dark
"
+
(
mobile
?
"
w-100
"
:
"
w-20
"
)}
disabled
=
{
isSubmitting
}
>
Login
<
/button
>
<
/div
>
<
div
className
=
""
>
<
Link
to
=
"
/signup
"
>
비밀번호를
잊으셨나요
?
<
/Link> /
<
Link
to
=
"
/signup
"
>
회원이
아니신가요
?
<
/Link
>
<
button
type
=
"
submit
"
className
=
{
"
btn btn-dark
"
+
(
mobile
?
"
w-100
"
:
"
w-20
"
)}
disabled
=
{
isSubmitting
}
>
Login
<
/button
>
<
button
><
Link
to
=
"
/home
"
>
홈
<
/Link></
button
>
<
div
><
/div
>
<
Link
to
=
"
/find
"
>
비밀번호를
잊으셨나요
?
<
/Link
>
<
div
><
/div
>
<
Link
to
=
"
/signup
"
>
회원이
아니신가요
?
<
/Link
>
<
/div
>
<
/form
>
)}
...
...
server/client/src/Pages/SignupPage.js
View file @
f10c71ec
import
React
,
{
useState
}
from
'
react
'
;
import
{
Formik
}
from
'
formik
'
;
import
{
Field
,
Formik
}
from
'
formik
'
;
import
*
as
Yup
from
'
yup
'
;
import
axios
from
'
axios
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
function
Signup
()
{
const
[
state
,
setState
]
=
useState
(
false
);
const
[
state
,
setState
]
=
useState
(
false
);
if
(
state
)
{
if
(
state
)
{
return
<
Redirect
to
=
"
/login
"
/>
;
}
}
return
(
<
div
className
=
"
d-flex flex-column justify-content-between vh-100
"
>
<
Formik
initialValues
=
{{
name
:
''
,
id
:
''
,
password
:
''
,
password2
:
''
}}
initialValues
=
{{
name
:
''
,
id
:
''
,
password
:
''
,
password2
:
''
,
question
:
''
,
answer
:
''
}}
validationSchema
=
{
Yup
.
object
({
name
:
Yup
.
string
()
.
required
(
'
이름을 입력해주세요.
'
),
...
...
@@ -28,21 +28,23 @@ function Signup() {
.
required
(
'
비밀번호를 다시 입력해주세요.
'
)
.
min
(
8
,
'
8자 이상 입력해주세요.
'
)
.
oneOf
([
Yup
.
ref
(
"
password
"
),
null
],
'
비밀번호가 일치하지 않습니다.
'
),
answer
:
Yup
.
string
()
.
required
(
'
답변을 입력해주세요.
'
),
})}
onSubmit
=
{(
values
,
{
setSubmitting
})
=>
{
axios
({
method
:
'
post
'
,
url
:
'
/users
'
,
data
:
values
,
method
:
'
post
'
,
url
:
'
/users
'
,
data
:
values
,
}).
then
(
res
=>
{
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
회원가입이 완료되었습니다!
"
)
if
(
res
.
status
===
404
)
return
alert
(
res
.
data
.
error
)
alert
(
"
회원가입이 완료되었습니다!
"
)
setState
(
true
);
setState
(
true
);
})
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
.
catch
(
err
=>
{
alert
(
err
.
error
)
});
setTimeout
(()
=>
{
setSubmitting
(
false
);
...
...
@@ -64,7 +66,7 @@ function Signup() {
type
=
"
text
"
name
=
"
name
"
{...
getFieldProps
(
'
name
'
)}
placeholder
=
"
Input Name
"
/>
placeholder
=
"
이름
"
/>
{
touched
.
name
&&
errors
.
name
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
name
}
<
/div
>
)
:
null
}
...
...
@@ -72,10 +74,10 @@ function Signup() {
<
div
className
=
"
form-group mb-4
"
>
<
input
className
=
{(
touched
.
id
&&
errors
.
id
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
number
"
type
=
"
text
"
name
=
"
id
"
{...
getFieldProps
(
'
id
'
)}
placeholder
=
"
Input Student Id
"
placeholder
=
"
학번/교번
"
/>
{
touched
.
id
&&
errors
.
id
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
id
}
<
/div
>
...
...
@@ -87,7 +89,7 @@ function Signup() {
type
=
"
password
"
name
=
"
password
"
{...
getFieldProps
(
'
password
'
)}
placeholder
=
"
Input Password
"
placeholder
=
"
비밀번호
"
/>
{
touched
.
password
&&
errors
.
password
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
password
}
<
/div
>
...
...
@@ -99,17 +101,37 @@ function Signup() {
type
=
"
password
"
name
=
"
password2
"
{...
getFieldProps
(
'
password2
'
)}
placeholder
=
"
Input Confirm Password
"
placeholder
=
"
비밀번호 확인
"
/>
{
touched
.
password2
&&
errors
.
password2
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
password2
}
<
/div
>
)
:
null
}
<
/div
>
<
div
className
=
"
form-group mb-4
"
>
<
label
>
본인
확인
질문
<
/label
>
<
Field
as
=
"
select
"
name
=
"
question
"
>
<
option
value
=
""
>
질문을
선택하세요
<
/option
>
<
option
value
=
"
life
"
>
자신의
인생
좌우명은
?
<
/option
>
<
option
value
=
"
school
"
>
자신이
다녔던
초등학교의
이름은
?
<
/option
>
<
option
value
=
"
place
"
>
기억에
남는
추억의
장소는
?
<
/option
>
<
/Field
>
<
/div
>
<
div
className
=
"
form-group mb-4
"
>
<
input
className
=
{(
touched
.
answer
&&
errors
.
answer
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
text
"
name
=
"
answer
"
{...
getFieldProps
(
'
answer
'
)}
placeholder
=
"
Input answer
"
/>
{
touched
.
answer
&&
errors
.
answer
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
answer
}
<
/div
>
)
:
null
}
<
/div
>
<
button
type
=
"
submit
"
className
=
"
btn btn-dark
"
disabled
=
{
isSubmitting
}
>
Sign
Up
<
/button
>
<
button
><
Link
to
=
"
/login
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/
"
>
홈
<
/Link></
button
>
<
button
class
=
"
btn btn-light
"
><
Link
to
=
"
/login
"
>
로그인
<
/Link></
button
>
<
button
class
=
"
btn btn-light
"
><
Link
to
=
"
/
"
>
홈
<
/Link></
button
>
<
/form
>
<
/div
>
)}
...
...
server/client/src/index.js
View file @
f10c71ec
...
...
@@ -10,6 +10,8 @@ import { PrivateRoute } from './Components/PrivateRoute';
import
Login
from
'
./Pages/LoginPage
'
;
import
Home
from
'
./Pages/HomePage
'
;
import
Signup
from
'
./Pages/SignupPage
'
;
import
Find
from
'
./Pages/FindPage
'
;
import
Change
from
'
./Pages/ChangePage
'
;
import
Apply
from
'
./Pages/ApplyPage
'
;
import
Check
from
'
./Pages/CheckPage
'
;
import
Notice
from
'
./Pages/NoticePage
'
;
...
...
@@ -25,11 +27,14 @@ ReactDOM.render(
<
Route
path
=
"
/login
"
component
=
{
Login
}
/
>
<
Route
path
=
"
/home
"
component
=
{
Home
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
Signup
}
/
>
<
Route
path
=
"
/find
"
component
=
{
Find
}
/
>
<
Route
path
=
"
/change
"
component
=
{
Change
}
/
>
<
Route
path
=
"
/apply
"
component
=
{
Apply
}
/
>
<
Route
path
=
"
/check
"
component
=
{
Check
}
/
>
<
Route
path
=
"
/check
/:id
"
component
=
{
Check
}
/
>
<
Route
path
=
"
/notice
"
component
=
{
Notice
}
/
>
<
Redirect
path
=
"
/
login
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/home
"
to
=
"
/
"
/>
<
Redirect
path
=
"
/change/:id
"
to
=
"
/change
"
/>
<
/Switch
>
<
/Router>
,
document
.
getElementById
(
'
root
'
)
...
...
server/routes/login.js
View file @
f10c71ec
...
...
@@ -2,6 +2,7 @@ const express = require('express');
const
User
=
require
(
'
../schemas/user
'
);
const
bcrypt
=
require
(
"
bcrypt
"
);
const
jwt
=
require
(
'
jsonwebtoken
'
);
const
user
=
require
(
'
../schemas/user
'
);
const
router
=
express
.
Router
();
...
...
@@ -19,11 +20,11 @@ router.get('/', function (req, res, next) {
router
.
post
(
'
/
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/login post request
'
,
req
.
body
)
User
.
findOne
({
id
:
req
.
body
.
id
},
'
id password
'
,
function
(
err
,
users
)
{
User
.
findOne
({
id
:
req
.
body
.
id
},
'
id password
name
'
,
function
(
err
,
users
)
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
!
users
)
{
return
res
.
status
(
404
).
json
({
error
:
'
해당
아이디가
존재하지 않습니다.
'
});
return
res
.
status
(
404
).
json
({
error
:
'
해당
학번이
존재하지 않습니다.
'
});
}
bcrypt
.
compare
(
req
.
body
.
password
,
users
.
password
,
function
(
err
,
result
)
{
...
...
@@ -34,7 +35,7 @@ router.post('/', function (req, res, next) {
if
(
result
)
{
const
token
=
jwt
.
sign
({
id
:
users
.
id
,
id
:
users
.
id
,
},
process
.
env
.
JWT_SECRET
,
{
expiresIn
:
'
1m
'
,
});
...
...
@@ -49,4 +50,20 @@ router.post('/', function (req, res, next) {
})
});
router
.
post
(
'
/find
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/find post request
'
,
req
.
body
)
User
.
findOne
({
id
:
req
.
body
.
id
},
'
id question answer
'
,
function
(
err
,
users
)
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
!
users
)
return
res
.
status
(
404
).
json
({
error
:
'
해당 학번이 존재하지 않습니다.
'
});
if
(
users
.
question
===
req
.
body
.
question
)
{
if
(
users
.
answer
===
req
.
body
.
answer
)
{
return
res
.
status
(
201
).
json
({
users
});
}
return
res
.
status
(
404
).
json
({
error
:
'
답변이 일치하지 않습니다.
'
});
}
return
res
.
status
(
404
).
json
({
error
:
'
질문을 다시 선택해주세요.
'
});
})
});
module
.
exports
=
router
;
server/routes/reserves.js
0 → 100644
View file @
f10c71ec
const
express
=
require
(
'
express
'
);
const
Reserve
=
require
(
'
../schemas/reserve
'
);
const
{
verifyToken
}
=
require
(
'
./middlewares
'
);
const
router
=
express
.
Router
();
router
.
post
(
'
/
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/reserve post req.body
'
,
req
.
body
)
const
reserve
=
new
Reserve
({
date
:
req
.
body
.
date
,
time
:
req
.
body
.
time
,
room
:
req
.
body
.
room
,
name
:
req
.
body
.
name
,
id
:
req
.
body
.
_id
,
reason
:
req
.
body
.
reason
,
member
:
req
.
body
.
member
,
approve
:
req
.
body
.
approve
,
num
:
req
.
body
.
num
,
});
reserve
.
save
()
.
then
((
result
)
=>
{
console
.
log
(
result
);
res
.
status
(
201
).
json
(
result
);
})
.
catch
((
err
)
=>
{
console
.
error
(
err
);
next
(
err
);
});
});
// router.get('/:_id', verifyToken, function (req, res, next) {
router
.
get
(
'
/:_id
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/reserves get req.params
'
,
req
.
params
)
Reserve
.
find
({
id
:
req
.
params
.
_id
},
function
(
err
,
reserve
)
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
console
.
log
(
'
reserve list
'
,
reserve
)
res
.
status
(
201
).
json
(
reserve
);
})
});
router
.
delete
(
'
/:_id
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/reserves delete req.params
'
,
req
.
params
)
Reserve
.
findOne
({
_id
:
req
.
params
.
_id
},
function
(
err
,
reserve
)
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
reserve
.
remove
()
.
then
(()
=>
{
console
.
log
();
res
.
status
(
201
).
json
();
})
.
catch
((
err
)
=>
{
console
.
error
(
err
);
next
(
err
);
});
})
});
module
.
exports
=
router
;
server/routes/users.js
View file @
f10c71ec
...
...
@@ -11,13 +11,15 @@ router.post('/', function (req, res, next) {
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
users
)
{
return
res
.
status
(
404
).
json
({
error
:
'
이미 존재하는
아이디
입니다.
'
})
return
res
.
status
(
404
).
json
({
error
:
'
이미 존재하는
학번
입니다.
'
})
};
const
user
=
new
User
({
name
:
req
.
body
.
name
,
id
:
req
.
body
.
id
,
password
:
req
.
body
.
password
,
question
:
req
.
body
.
question
,
answer
:
req
.
body
.
answer
,
});
user
.
save
()
...
...
@@ -31,4 +33,32 @@ router.post('/', function (req, res, next) {
});
})
});
router
.
put
(
'
/change/:id
'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
'
/change put req.body
'
,
req
.
params
)
User
.
findOne
({
_id
:
req
.
params
.
id
},
'
password
'
,
function
(
err
,
user
)
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
bcrypt
.
compare
(
req
.
body
.
password
,
user
.
password
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
log
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
}
if
(
result
)
{
return
res
.
status
(
404
).
json
({
error
:
'
새로운 비밀번호를 입력해주세요.
'
})
}
});
user
.
password
=
req
.
body
.
password
;
user
.
save
()
.
then
((
result
)
=>
{
console
.
log
(
result
);
res
.
status
(
201
).
json
(
result
);
})
.
catch
((
err
)
=>
{
console
.
error
(
err
);
next
(
err
);
});
})
});
module
.
exports
=
router
;
server/schemas/reserve.js
View file @
f10c71ec
const
mongoose
=
require
(
'
mongoose
'
);
const
{
Schema
}
=
mongoose
;
const
{
Types
:
{
ObjectId
}
}
=
Schema
;
const
reserveSchema
=
new
Schema
({
date
:
{
type
:
String
,
},
time
:
{
type
:
String
,
},
room
:{
type
:
String
,
},
name
:
{
//대표자 이름
type
:
String
,
},
id
:{
type
:
Number
,
},
reason
:
{
type
:
String
,
},
member
:
{
type
:
String
,
},
approve
:
{
type
:
Boolean
,
},
num
:
{
type
:
Number
,
},
id
:
{
type
:
ObjectId
,
required
:
true
,
ref
:
'
User
'
,
},
date
:
{
type
:
String
,
},
time
:
{
type
:
String
,
},
room
:
{
type
:
String
,
},
name
:
{
//대표자 이름
type
:
String
,
},
reason
:
{
type
:
String
,
},
member
:
{
type
:
String
,
},
approve
:
{
type
:
Boolean
,
default
:
false
,
},
num
:
{
type
:
Number
,
},
});
module
.
exports
=
mongoose
.
model
(
'
Reserve
'
,
reserveSchema
);
server/schemas/user.js
View file @
f10c71ec
...
...
@@ -12,6 +12,17 @@ const userSchema = new Schema({
type
:
String
,
},
role
:
{
type
:
String
,
default
:
'
user
'
,
},
answer
:{
type
:
String
,
},
question
:
{
type
:
String
,
},
id
:
{
type
:
Number
,
required
:
true
,
...
...
@@ -20,22 +31,22 @@ const userSchema = new Schema({
});
userSchema
.
pre
(
"
save
"
,
function
(
next
)
{
let
user
=
this
;
//User모델 자체를 가르킴.
//model 안의 paswsword가 변경 또는 생성될 때 암호화
if
(
user
.
isModified
(
"
password
"
))
{
bcrypt
.
genSalt
(
saltRounds
,
function
(
err
,
salt
)
{
let
user
=
this
;
//User모델 자체를 가르킴.
//model 안의 paswsword가 변경 또는 생성될 때 암호화
if
(
user
.
isModified
(
"
password
"
))
{
bcrypt
.
genSalt
(
saltRounds
,
function
(
err
,
salt
)
{
if
(
err
)
return
next
(
err
);
bcrypt
.
hash
(
user
.
password
,
salt
,
function
(
err
,
hash
)
{
if
(
err
)
return
next
(
err
);
bcrypt
.
hash
(
user
.
password
,
salt
,
function
(
err
,
hash
)
{
if
(
err
)
return
next
(
err
);
user
.
password
=
hash
;
next
();
});
user
.
password
=
hash
;
next
();
});
}
else
{
next
();
}
});
});
}
else
{
next
();
}
});
module
.
exports
=
mongoose
.
model
(
'
User
'
,
userSchema
);
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