Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정성훈
/
MEALKHU
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
swa07016
2020-06-15 02:16:32 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ff18048389f7a1465b4340e267805f1be0fa3c23
ff180483
1 parent
20a2ce4d
중복 가입 방지 구현
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
23 deletions
client/src/pages/SigninPage.js
client/src/pages/SignupPage.js
server.js
client/src/pages/SigninPage.js
View file @
ff18048
...
...
@@ -36,7 +36,6 @@ const SigninPage = (props) => {
cookie
.
save
(
'username'
,
response
.
username
,
{
expires
})
alert
(
'Login success'
);
props
.
history
.
push
(
'/mypick'
);
}
else
if
(
response
.
message
===
"user does not exist"
){
alert
(
'User does not exist'
);
...
...
client/src/pages/SignupPage.js
View file @
ff18048
...
...
@@ -37,12 +37,18 @@ const SigninPage = (props) => {
fetch
(
"http://localhost:3000/api/signup"
,
signup_info
)
.
then
(
response
=>
response
.
json
())
.
then
(
json
=>
{
if
(
json
.
code
===
200
)
{
if
(
json
.
message
===
'success'
)
{
alert
(
'회원가입에 성공했습니다.'
);
props
.
history
.
push
(
'/signin'
);
}
else
if
(
json
.
code
===
400
)
{
}
else
if
(
json
.
message
===
'user exist'
)
{
alert
(
'이미 존재하는 유저입니다'
);
setUsername
(
''
);
setPassword
(
''
);
}
else
{
alert
(
'회원가입에 실패했습니다.'
);
setUsername
(
''
);
setPassword
(
''
);
}
})
}
...
...
server.js
View file @
ff18048
...
...
@@ -40,28 +40,40 @@ app.get("/api/datas", (req, res) => {
res
.
send
(
iconv
.
decode
(
dataBuffer
,
"EUC-KR"
).
toString
());
});
// ???? ???? ??
// signup
app
.
post
(
"/api/signup"
,
(
req
,
res
)
=>
{
let
sql
=
"INSERT INTO USER (name, pw) VALUES(?, ?)"
;
let
plainPassword
=
req
.
body
.
password
;
bcrypt
.
hash
(
plainPassword
,
saltRounds
,
function
(
err
,
hash
)
{
const
params
=
[
req
.
body
.
username
,
hash
];
connection
.
query
(
sql
,
params
,
(
err
,
rows
,
fields
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
res
.
send
({
code
:
400
,
message
:
"error"
,
});
}
else
{
res
.
send
({
code
:
200
,
message
:
"success"
,
let
sql_usercheck
=
`SELECT * FROM USER WHERE name='
${
req
.
body
.
username
}
';`
;
connection
.
query
(
sql_usercheck
,
(
err
,
rows
,
fields
)
=>
{
console
.
log
(
rows
);
if
(
rows
.
length
!==
0
)
{
return
res
.
json
({
code
:
400
,
message
:
'user exist'
})
}
else
{
let
sql
=
"INSERT INTO USER (name, pw) VALUES(?, ?)"
;
let
plainPassword
=
req
.
body
.
password
;
bcrypt
.
hash
(
plainPassword
,
saltRounds
,
function
(
err
,
hash
)
{
const
params
=
[
req
.
body
.
username
,
hash
];
connection
.
query
(
sql
,
params
,
(
err
,
rows
,
fields
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
res
.
send
({
code
:
400
,
message
:
"error"
,
});
}
else
{
res
.
send
({
code
:
200
,
message
:
"success"
,
});
}
});
}
}
);
})
;
}
);
}
})
});
app
.
post
(
"/api/signin"
,
(
req
,
res
)
=>
{
...
...
Please
register
or
login
to post a comment