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
be388b9e
Commit
be388b9e
authored
Jul 14, 2021
by
Kim, Chaerin
Browse files
.
parent
aa59e0a7
Changes
9
Hide whitespace changes
Inline
Side-by-side
client/src/apis/user.api.js
View file @
be388b9e
import
axios
from
"
axios
"
;
import
axios
from
"
axios
"
;
import
endpoints
from
"
./endpoints
"
;
import
endpoints
from
"
./endpoints
"
;
const
login
=
async
(
email
,
passwor
d
)
=>
{
const
login
=
async
(
payloa
d
)
=>
{
const
payload
=
{
email
,
password
}
;
const
{
data
}
=
await
axios
.
post
(
`
${
endpoints
.
API_BASE_URL
}
/login`
,
payload
)
;
cons
t
{
data
}
=
await
axios
.
post
(
`
${
endpoints
.
API_BASE_URL
}
/`
,
payload
);
cons
ole
.
log
(
data
);
return
data
;
return
data
;
};
};
export
default
login
;
const
signup
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
post
(
`
${
endpoints
.
API_BASE_URL
}
/signup`
,
payload
);
return
data
;
};
const
userApi
=
{
login
,
signup
};
export
default
userApi
;
client/src/components/Login.js
View file @
be388b9e
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Redirect
}
from
"
react-router-dom
"
;
import
login
from
"
../apis/user.api
"
;
import
login
from
"
../apis/user.api
"
;
const
INIT_USER
=
{
const
INIT_USER
=
{
email
:
""
,
email
:
""
,
...
@@ -20,22 +21,25 @@ const Login = () => {
...
@@ -20,22 +21,25 @@ const Login = () => {
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
;
const
{
name
,
value
}
=
event
.
target
;
setUser
({
...
user
,
[
name
]:
value
});
setUser
({
...
user
,
[
name
]:
value
});
console
.
log
(
user
);
}
}
async
function
handleSubmit
()
{
async
function
handleSubmit
(
e
)
{
e
.
preventDefault
();
try
{
try
{
// setLoading(true);
// setLoading(true);
// setError("");
// setError("");
const
success
=
await
login
(
user
.
email
,
user
.
password
);
const
data
=
await
login
(
user
);
console
.
log
(
user
);
console
.
log
(
data
);
setSuccess
(
success
);
setSuccess
(
true
);
}
catch
(
error
)
{
}
catch
(
error
)
{
// catchErrors(error, setError);
// catchErrors(error, setError);
}
finally
{
}
finally
{
// setLoading(false);
// setLoading(false);
}
}
}
}
if
(
success
)
{
return
<
Redirect
to
=
"
/user
"
/>
;
}
const
{
email
,
password
}
=
user
;
const
{
email
,
password
}
=
user
;
...
...
client/src/components/SignUp.js
View file @
be388b9e
import
axios
from
"
axios
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
const
INIT_USER
=
{
const
INIT_USER
=
{
...
@@ -37,10 +38,11 @@ const Signup = () => {
...
@@ -37,10 +38,11 @@ const Signup = () => {
async
function
handleSubmit
()
{
async
function
handleSubmit
()
{
try
{
try
{
const
data
=
await
axios
.
post
(
"
https://localhost:8080/api/room/1/1
"
,
user
)
// setLoading(true);
// setLoading(true);
// setError("");
// setError("");
// const success = await login(user.email, user.password);
// const success = await login(user.email, user.password);
console
.
log
(
user
);
console
.
log
(
data
);
setSuccess
(
success
);
setSuccess
(
success
);
}
catch
(
error
)
{
}
catch
(
error
)
{
// catchErrors(error, setError);
// catchErrors(error, setError);
...
...
controllers/room.controller.js
View file @
be388b9e
...
@@ -3,7 +3,7 @@ import config from "../config/app.config.js";
...
@@ -3,7 +3,7 @@ import config from "../config/app.config.js";
const
login
=
async
(
req
,
res
)
=>
{
const
login
=
async
(
req
,
res
)
=>
{
try
{
try
{
console
.
log
(
"
login
=
"
,
req
.
body
);
console
.
log
(
"
room
=
"
,
req
.
body
);
res
.
json
(
"
안녕
"
);
res
.
json
(
"
안녕
"
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
controllers/user.controller.js
View file @
be388b9e
import
{
User
}
from
"
../models/index.js
"
;
import
{
User
}
from
"
../models/index.js
"
;
import
config
from
"
../config/app.config.js
"
;
import
config
from
"
../config/app.config.js
"
;
const
test
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
req
);
res
.
json
(
"
안녕
"
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
res
.
status
(
500
).
send
(
"
test 중 에러
"
);
}
};
const
login
=
async
(
req
,
res
)
=>
{
const
login
=
async
(
req
,
res
)
=>
{
try
{
try
{
console
.
log
(
"
login=
"
,
req
.
body
);
console
.
log
(
"
login=
"
,
req
.
body
);
const
{
email
,
password
}
=
req
.
body
;
const
{
email
,
password
}
=
req
.
body
;
const
user
=
await
User
.
scope
(
"
password
"
).
findOne
({
where
:
email
});
const
user
=
await
User
.
findOne
({
where
:
{
email
:
email
}
});
if
(
!
user
)
if
(
!
user
)
return
res
.
status
(
422
).
send
(
`
${
email
}
사용자가 존재하지 않습니다.`
);
return
res
.
status
(
422
).
send
(
`
${
email
}
사용자가 존재하지 않습니다.`
);
...
@@ -29,6 +39,17 @@ const login = async (req, res) => {
...
@@ -29,6 +39,17 @@ const login = async (req, res) => {
}
}
};
};
const
signup
=
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
sign up=
"
,
req
.
body
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
res
.
status
(
500
).
send
(
"
회원가입 중 에러
"
);
}
};
export
default
{
export
default
{
test
,
login
,
login
,
signup
,
};
};
index.js
View file @
be388b9e
...
@@ -14,13 +14,12 @@ sequelize
...
@@ -14,13 +14,12 @@ sequelize
.
sync
({
force
:
true
})
.
sync
({
force
:
true
})
.
then
(
async
()
=>
{
.
then
(
async
()
=>
{
console
.
log
(
"
DB 연결 성공
"
);
console
.
log
(
"
DB 연결 성공
"
);
// await User.create({
await
User
.
create
({
// id: 0,
name
:
"
admin
"
,
// name: "admin",
email
:
"
admin
"
,
// email: "admin",
password
:
"
admin!
"
,
// password: "admin!",
gender
:
0
,
// gender: 0,
});
// });
app
.
listen
(
appConfig
.
port
,
()
=>
{
app
.
listen
(
appConfig
.
port
,
()
=>
{
console
.
log
(
`Server is running on port
${
appConfig
.
port
}
`
);
console
.
log
(
`Server is running on port
${
appConfig
.
port
}
`
);
...
...
models/user.model.js
View file @
be388b9e
...
@@ -8,6 +8,7 @@ const UserModel = (sequelize) => {
...
@@ -8,6 +8,7 @@ const UserModel = (sequelize) => {
id
:
{
id
:
{
type
:
DataTypes
.
INTEGER
,
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
},
name
:
{
name
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
...
...
routes/room.route.js
View file @
be388b9e
...
@@ -3,6 +3,6 @@ import roomCrtl from "../controllers/room.controller.js";
...
@@ -3,6 +3,6 @@ import roomCrtl from "../controllers/room.controller.js";
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
).
ge
t
(
roomCrtl
.
login
);
router
.
route
(
"
/
"
).
pos
t
(
roomCrtl
.
login
);
export
default
router
;
export
default
router
;
routes/user.route.js
View file @
be388b9e
...
@@ -3,6 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
...
@@ -3,6 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
test
);
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