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
search-page
Commits
f87d8251
Commit
f87d8251
authored
Jan 13, 2021
by
Lee SeoYeon
Browse files
.
parent
fe26a747
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
client/.eslintcache
View file @
f87d8251
This diff is collapsed.
Click to expand it.
client/src/Components/Login.js
View file @
f87d8251
import
React
,
{
useState
,
useEffect
}
from
'
react
'
import
{
Alert
,
Col
,
Container
,
Form
,
Row
,
Button
,
Spinner
}
from
"
react-bootstrap
"
;
import
axios
from
"
axios
"
;
import
catchErrors
from
'
../utils/catchErrors
'
;
import
{
Redirect
}
from
'
react-router-dom
'
;
import
{
handleLogin
}
from
'
../utils/auth
'
;
import
{
Alert
,
Col
,
Container
,
Form
,
Row
,
Button
,
Spinner
}
from
"
react-bootstrap
"
import
axios
from
"
axios
"
import
catchErrors
from
'
../utils/catchErrors
'
import
{
Redirect
}
from
'
react-router-dom
'
import
{
handleLogin
}
from
'
../utils/auth
'
const
INIT_USER
=
{
...
...
client/src/Components/Signup.js
View file @
f87d8251
import
React
,
{
useState
,
useEffect
}
from
'
react
'
import
{
Alert
,
Col
,
Container
,
Form
,
Row
,
Button
}
from
"
react-bootstrap
"
;
import
axios
from
"
axios
"
;
import
catchErrors
from
'
../utils/catchErrors
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
{
Col
,
Container
,
Form
,
Row
,
Button
,
Alert
}
from
"
react-bootstrap
"
import
axios
from
"
axios
"
import
catchErrors
from
'
../utils/catchErrors
'
import
{
Redirect
}
from
'
react-router-dom
'
const
INIT_USER
=
{
name
:
''
,
...
...
@@ -32,13 +32,17 @@ function Signup() {
setError
(
''
)
const
response
=
await
axios
.
post
(
'
/api/users/signup
'
,
user
)
console
.
log
(
response
.
data
)
setUser
(
INIT_USER
)
console
.
log
(
user
)
// setUser(INIT_USER)
setSuccess
(
true
)
}
catch
(
error
)
{
console
.
log
(
error
)
catchErrors
(
error
,
setError
)
}
}
if
(
success
)
{
alert
(
'
회원가입 되었습니다.
'
)
return
<
Redirect
to
=
'
/
'
/>
}
...
...
client/src/index.js
View file @
f87d8251
...
...
@@ -15,10 +15,6 @@ import {
}
from
"
react-router-dom
"
;
import
axios
from
'
axios
'
;
axios
.
defaults
.
validateStatus
=
function
(
status
){
return
status
<
500
;
}
ReactDOM
.
render
(
<
React
.
StrictMode
>
<
Router
>
...
...
server/controllers/auth.controller.js
View file @
f87d8251
import
User
from
"
../models/User.js
"
import
bcrypt
from
"
bcryptjs
"
import
jwt
from
"
jsonwebtoken
"
;
import
config
from
"
../config.js
"
;
import
jwt
from
"
jsonwebtoken
"
import
config
from
"
../config.js
"
const
login
=
async
(
req
,
res
)
=>
{
const
{
email
,
password
}
=
req
.
body
//구조분해해서 하나씩
...
...
server/controllers/user.controller.js
View file @
f87d8251
...
...
@@ -4,7 +4,7 @@ import isEmail from "validator/lib/isEmail.js"
import
bcrypt
from
"
bcryptjs
"
;
import
multer
from
"
multer
"
;
const
upload
=
multer
({
dest
:
'
uploads/
'
})
const
upload
=
multer
({
dest
:
'
uploads/
'
})
//미들웨어
const
profileUpload
=
upload
.
fields
([
{
name
:
'
avatar
'
,
maxCount
:
1
},
...
...
@@ -12,9 +12,9 @@ const profileUpload = upload.fields([
])
const
signup
=
async
(
req
,
res
)
=>
{
const
{
name
,
email
,
password
}
=
req
.
body
const
{
name
,
email
,
password
}
=
req
.
body
//구조분해해서 하나씩
console
.
log
(
name
,
email
,
password
)
try
{
try
{
//적어도 3개 맥시멈 10개 가 아니면
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
10
}))
{
return
res
.
status
(
422
).
send
(
'
이름은 3-10자 사이입니다
'
)
}
else
if
(
!
isLength
(
password
,
{
min
:
6
}))
{
...
...
@@ -31,10 +31,10 @@ const signup = async (req, res) => {
name
,
email
,
password
:
hash
}).
save
()
}).
save
()
//save하면 몽고 db에 들어간다 save method가 promise
console
.
log
(
newUser
)
res
.
json
(
newUser
)
}
catch
(
error
)
{
res
.
json
(
newUser
)
//json형식으로 바꿔서 문자열로 보낸다 client쪽으로
}
catch
(
error
)
{
//다른 과정에서 에러가 나면 실행
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
회원가입 에러
'
)
}
...
...
@@ -70,7 +70,7 @@ const userById = async (req, res, next, id) => {
res
.
status
(
404
).
send
(
'
사용자를 찾을 수 없습니다
'
)
}
req
.
profile
=
user
next
()
next
()
//만나는 순간 다음 미들웨어로 진행 없으면 가만히 있는다
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
사용자 아이디 검색 실패
'
)
...
...
server/routes/auth.routes.js
View file @
f87d8251
import
express
from
"
express
"
import
authCtrl
from
"
../controllers/auth.controller.js
"
;
import
authCtrl
from
"
../controllers/auth.controller.js
"
const
router
=
express
.
Router
()
...
...
server/routes/user.routes.js
View file @
f87d8251
import
express
from
"
express
"
;
import
userCtrl
from
"
../controllers/user.controller.js
"
;
import
express
from
"
express
"
import
userCtrl
from
"
../controllers/user.controller.js
"
const
router
=
express
.
Router
()
...
...
server/server.js
View file @
f87d8251
...
...
@@ -14,10 +14,6 @@ app.use(express.json())
app
.
use
(
userRouter
)
app
.
use
(
authRouter
)
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
send
(
'
Hello world, 안녕하세요.
'
)
})
app
.
listen
(
3001
,
()
=>
{
console
.
log
(
'
Listening on port 3001
'
)
})
\ 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