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
bora-it
Commits
cb8b006f
Commit
cb8b006f
authored
Jul 26, 2021
by
seoyeon
Browse files
0726
parent
477e56fd
Changes
5
Hide whitespace changes
Inline
Side-by-side
client/package.json
View file @
cb8b006f
...
...
@@ -9,6 +9,7 @@
"@testing-library/user-event"
:
"^12.1.10"
,
"axios"
:
"^0.21.1"
,
"bootstrap"
:
"^5.0.2"
,
"nanoid"
:
"^3.1.23"
,
"node-sass"
:
"^6.0.1"
,
"react"
:
"^17.0.2"
,
"react-dom"
:
"^17.0.2"
,
...
...
client/src/components/SignUp.js
View file @
cb8b006f
...
...
@@ -42,12 +42,14 @@ const Signup = () => {
async
function
handleSubmit
()
{
try
{
const
data
=
await
axios
.
post
(
"
/api/room/1/1
"
,
user
)
// setLoading(true);
// setError("");
// const success = await login(user.email, user.password);
const
data
=
await
userApi
.
signup
(
user
)
// const data = await axios.post("https://localhost:8080/api/room/1/1",user)
setLoading
(
true
);
setError
(
""
);
// const success = await login(user.email, user.password);
// const data = await axios.post("/api/room/1/1",user)
console
.
log
(
data
);
//
se
s
tSuccess(
success
);
setSuccess
(
true
);
}
catch
(
error
)
{
// catchErrors(error, setError);
}
finally
{
...
...
controllers/user.controller.js
View file @
cb8b006f
import
{
User
}
from
"
../models/index.js
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
config
from
"
../config/app.config.js
"
;
import
{
User
}
from
'
../models/index.js
'
import
jwt
from
'
jsonwebtoken
'
import
config
from
'
../config/app.config.js
'
import
isLength
from
'
validator/lib/isLength.js
'
import
bcrypt
from
"
bcryptjs
"
;
const
test
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
req
);
res
.
json
(
"
안녕
"
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
res
.
status
(
500
).
send
(
"
test 중 에러
"
);
}
};
import
bcrypt
from
'
bcryptjs
'
const
login
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
login=
"
,
req
.
body
)
;
const
{
email
,
password
}
=
req
.
body
;
const
user
=
await
User
.
findOne
({
where
:
{
email
:
email
}
})
;
console
.
log
(
'
login=
'
,
req
.
body
)
const
{
email
,
password
}
=
req
.
body
const
user
=
await
User
.
findOne
({
where
:
{
email
:
email
}
})
if
(
!
user
)
return
res
.
status
(
422
).
send
(
`
${
email
}
사용자가 존재하지 않습니다.`
)
;
return
res
.
status
(
422
).
send
(
`
${
email
}
사용자가 존재하지 않습니다.`
)
const
passworMatch
=
await
user
.
comparePassword
(
password
)
;
const
passworMatch
=
await
user
.
comparePassword
(
password
)
if
(
passworMatch
)
{
const
token
=
jwt
.
sign
({
userID
:
user
.
id
},
config
.
jwtSecret
,
{
expiresIn
:
config
.
jwtExpires
,
})
;
})
res
.
cookie
(
config
.
cookieName
,
token
,
{
path
:
"
/
"
,
path
:
'
/
'
,
httpOnly
:
true
,
secure
:
true
,
})
;
res
.
json
({
user
})
;
})
res
.
json
({
user
})
}
else
{
res
.
status
(
401
).
send
(
"
비밀번호가 일치하지 않습니다.
"
);
res
.
status
(
401
).
send
(
'
비밀번호가 일치하지 않습니다.
'
)
}
}
catch
(
error
)
{
console
.
log
(
error
)
;
return
res
.
status
(
500
).
send
(
"
로그인 중 에러
"
);
console
.
log
(
error
)
return
res
.
status
(
500
).
send
(
'
로그인 중 에러
'
)
}
}
;
}
const
signup
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
sign up=
"
,
req
.
body
)
;
const
{
name
,
email
,
password
,
gender
,
phone
}
=
req
.
body
;
const
id
=
Math
.
floor
(
(
Math
.
random
()
*
(
9999
-
1000
)
+
1000
));
console
.
log
(
'
id:
'
,
id
)
const
Id
=
await
User
.
findOne
({
where
:
{
id
:
id
}})
console
.
log
(
"
Id 중복확인:
"
,
Id
)
while
(
Id
)
{
const
id
=
Math
.
floor
(
(
Math
.
random
()
*
(
9999
-
1000
)
+
1000
));
const
Id
=
await
User
.
findOne
({
where
:
{
id
:
id
}
})
;
}
const
user
=
await
User
.
findOne
({
where
:
{
email
:
email
}
})
;
console
.
log
(
'
sign up=
'
,
req
.
body
)
const
{
name
,
email
,
password
,
gender
,
phone
}
=
req
.
body
const
id
=
Math
.
floor
(
Math
.
random
()
*
(
9999
-
1000
)
+
1000
)
console
.
log
(
'
id:
'
,
id
)
const
Id
=
await
User
.
findOne
({
where
:
{
id
:
id
}
})
console
.
log
(
'
Id 중복확인:
'
,
Id
)
while
(
Id
)
{
const
id
=
Math
.
floor
(
Math
.
random
()
*
(
9999
-
1000
)
+
1000
)
const
Id
=
await
User
.
findOne
({
where
:
{
id
:
id
}
})
}
const
user
=
await
User
.
findOne
({
where
:
{
email
:
email
}
})
if
(
user
)
return
res
.
status
(
422
).
send
(
`
${
email
}
이미 존재하는 사용자입니다.`
)
;
return
res
.
status
(
422
).
send
(
`
${
email
}
이미 존재하는 사용자입니다.`
)
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
10
}))
{
return
res
.
status
(
422
).
send
(
'
이름은 3-10자 사이입니다
'
)
}
else
if
(
!
isLength
(
password
,
{
min
:
6
})){
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
10
}))
{
return
res
.
status
(
422
).
send
(
'
이름은 3-10자 사이입니다
'
)
}
else
if
(
!
isLength
(
password
,
{
min
:
6
}))
{
return
res
.
status
(
422
).
send
(
'
비밀번호는 6자이상 입니다
'
)
}
else
if
(
!
isLength
(
email
,{
min
:
3
,
max
:
10
}))
{
}
else
if
(
!
isLength
(
email
,
{
min
:
3
,
max
:
10
}))
{
return
res
.
status
(
422
).
send
(
'
아이디는 3-10자 사이입니다
'
)
}
const
newUser
=
User
.
create
({
id
:
id
,
const
hash
=
await
bcrypt
.
hash
(
password
,
10
)
const
newUser
=
await
User
.
create
({
id
:
id
,
name
:
name
,
email
:
email
,
password
:
p
as
sword
,
password
:
h
as
h
,
gender
:
gender
,
phone
:
phone
,
});
}).
then
(
_
=>
console
.
log
(
"
회원가입 정보
"
,
id
,
name
,
email
,
hash
,
gender
,
phone
)
)
}
catch
(
error
)
{
console
.
log
(
error
)
;
return
res
.
status
(
500
).
send
(
"
회원가입 중 에러
"
);
console
.
log
(
error
)
return
res
.
status
(
500
).
send
(
'
회원가입 중 에러
'
)
}
}
;
}
export
default
{
test
,
login
,
signup
,
}
;
}
models/user.model.js
View file @
cb8b006f
...
...
@@ -24,12 +24,12 @@ const UserModel = (sequelize) => {
phone
:
{
type
:
DataTypes
.
INTEGER
,
},
img
:
{
type
:
DataTypes
.
STRING
,
},
roomNumber
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
},
//
img: {
//
type: DataTypes.STRING,
//
},
//
roomNumber: {
//
type: DataTypes.ARRAY(DataTypes.STRING),
//
},
},
{
timestamps
:
true
}
);
...
...
package.json
View file @
cb8b006f
...
...
@@ -24,7 +24,7 @@
"
express
"
:
"
4.17.1
"
,
"
http
"
:
"
0.0.1-security
"
,
"
jsonwebtoken
"
:
"
^8.5.1
"
,
"
nanoid
"
:
"
^3.1.2
0
"
,
"
nanoid
"
:
"
^3.1.2
3
"
,
"
nodemon
"
:
"
^2.0.7
"
,
"
pg
"
:
"
^8.6.0
"
,
"
pg-hstore
"
:
"
^2.3.4
"
,
...
...
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