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
042b0a4e
Commit
042b0a4e
authored
Jul 24, 2021
by
seoyeon
Browse files
0724
parent
d9089b86
Changes
7
Hide whitespace changes
Inline
Side-by-side
client/public/user.png
0 → 100644
View file @
042b0a4e
17.1 KB
client/src/components/Login.js
View file @
042b0a4e
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
userApi
from
"
../apis/user.api
"
;
import
userApi
from
"
../apis/user.api
"
;
// import catchErrors from "../context/catchError";
const
INIT_USER
=
{
const
INIT_USER
=
{
email
:
""
,
email
:
""
,
password
:
""
,
password
:
""
,
...
@@ -25,6 +26,7 @@ const Login = () => {
...
@@ -25,6 +26,7 @@ const Login = () => {
async
function
handleSubmit
(
e
)
{
async
function
handleSubmit
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
console
.
log
(
'
로그인
'
)
try
{
try
{
// setLoading(true);
// setLoading(true);
// setError("");
// setError("");
...
@@ -37,12 +39,9 @@ const Login = () => {
...
@@ -37,12 +39,9 @@ const Login = () => {
// setLoading(false);
// setLoading(false);
}
}
}
}
if
(
success
)
{
return
<
Redirect
to
=
"
/user
"
/>
;
}
if
(
success
)
{
if
(
success
)
{
alert
(
'
로그인 되었습니다
'
)
alert
(
'
로그인 되었습니다
'
)
return
<
Redirect
to
=
"
/user
"
/>
;
}
}
const
{
email
,
password
}
=
user
;
const
{
email
,
password
}
=
user
;
...
...
client/src/components/SignUp.js
View file @
042b0a4e
import
axios
from
"
axios
"
;
import
axios
from
"
axios
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
userApi
from
"
../apis/user.api
"
;
// import catchErrors from "../context/catchError";
// import auth from "../context/auth_context"
const
INIT_USER
=
{
const
INIT_USER
=
{
name
:
""
,
name
:
""
,
idNumber1
:
""
,
idNumber1
:
""
,
...
@@ -16,6 +19,7 @@ const Signup = () => {
...
@@ -16,6 +19,7 @@ const Signup = () => {
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
disabled
,
setDisabled
]
=
useState
(
false
);
const
[
disabled
,
setDisabled
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
useEffect
(()
=>
{
useEffect
(()
=>
{
setDisabled
(
setDisabled
(
...
@@ -38,21 +42,23 @@ const Signup = () => {
...
@@ -38,21 +42,23 @@ const Signup = () => {
async
function
handleSubmit
()
{
async
function
handleSubmit
()
{
try
{
try
{
const
data
=
await
axios
.
post
(
"
https://localhost:8080/api/room/1/1
"
,
user
)
const
data
=
await
userApi
.
signup
(
user
)
// setLoading(true);
// const data = await axios.post("https://localhost:8080/api/room/1/1",user)
// setError("");
setLoading
(
true
);
// const success = await login(user.email, user.password);
setError
(
""
);
// const success = await login(user.email, user.password);
console
.
log
(
data
);
console
.
log
(
data
);
setSuccess
(
success
);
//
se
s
tSuccess(success);
}
catch
(
error
)
{
}
catch
(
error
)
{
// catchErrors(error, setError);
// catchErrors(error, setError);
}
finally
{
}
finally
{
//
setLoading(false);
setLoading
(
false
);
}
}
}
}
if
(
success
)
{
if
(
success
)
{
alert
(
'
회원가입 되었습니다.
'
)
alert
(
'
회원가입 되었습니다.
'
)
return
<
Redirect
to
=
"
/
"
/>
;
}
}
...
...
client/src/context/catchError.js
0 → 100644
View file @
042b0a4e
function
catchErrors
(
error
,
displayError
)
{
let
errorMsg
if
(
error
.
response
)
{
errorMsg
=
error
.
response
.
data
console
.
log
(
errorMsg
)
}
else
if
(
error
.
requset
)
{
errorMsg
=
error
.
requset
console
.
log
(
errorMsg
)
}
else
{
errorMsg
=
error
.
message
console
.
log
(
errorMsg
)
}
displayError
(
errorMsg
)
}
export
default
catchErrors
controllers/user.controller.js
View file @
042b0a4e
...
@@ -45,8 +45,35 @@ const login = async (req, res) => {
...
@@ -45,8 +45,35 @@ const login = async (req, res) => {
const
signup
=
async
(
req
,
res
)
=>
{
const
signup
=
async
(
req
,
res
)
=>
{
try
{
try
{
console
.
log
(
"
sign up=
"
,
req
.
body
);
console
.
log
(
"
sign up=
"
,
req
.
body
);
const
{
id
,
name
,
email
,
password
,
gender
,
phone
}
=
req
.
body
;
const
{
name
,
email
,
password
,
gender
,
phone
}
=
req
.
body
;
const
user
=
User
.
create
({
id
,
name
,
email
,
password
,
gender
,
phone
});
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
}
이미 존재하는 사용자입니다.`
);
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
}))
{
return
res
.
status
(
422
).
send
(
'
아이디는 3-10자 사이입니다
'
)
}
const
newUser
=
User
.
create
({
id
:
id
,
name
:
name
,
email
:
email
,
password
:
password
,
gender
:
gender
,
phone
:
phone
,
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
return
res
.
status
(
500
).
send
(
"
회원가입 중 에러
"
);
return
res
.
status
(
500
).
send
(
"
회원가입 중 에러
"
);
...
...
models/user.model.js
View file @
042b0a4e
...
@@ -26,6 +26,7 @@ const UserModel = (sequelize) => {
...
@@ -26,6 +26,7 @@ const UserModel = (sequelize) => {
},
},
img
:
{
img
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
INTEGER
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
INTEGER
),
default
:
'
/user.png
'
},
},
roomNumber
:
{
roomNumber
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
type
:
DataTypes
.
ARRAY
(
DataTypes
.
STRING
),
...
...
routes/user.route.js
View file @
042b0a4e
...
@@ -6,5 +6,4 @@ const router = express.Router();
...
@@ -6,5 +6,4 @@ const router = express.Router();
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
signup
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
signup
);
router
.
route
(
"
/
"
).
post
(
userCtrl
.
signup
);
export
default
router
;
export
default
router
;
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