Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김대휘
/
Do-gether
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
김대휘
2020-06-25 11:59:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
54a78b9fa7fc4b3fb8fbde5a99bb5ee5fb0fa6aa
54a78b9f
1 parent
1b00f7ee
Login Check
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
7 deletions
client/src/pages/LoginPage.js
server.js
client/src/pages/LoginPage.js
View file @
54a78b9
...
...
@@ -54,12 +54,37 @@ const useStyles = makeStyles((theme) => ({
},
}));
export
default
function
LandingPage
()
{
export
default
function
LandingPage
(
props
)
{
const
classes
=
useStyles
();
const
[
userID
,
setUserID
]
=
useState
();
const
[
userPW
,
setUserPW
]
=
useState
();
const
loginApi
=
(
data
)
=>
{
return
fetch
(
"/api/login"
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
,
},
body
:
JSON
.
stringify
(
data
),
}).
then
((
response
)
=>
response
.
json
());
};
const
handleLogin
=
()
=>
{
if
(
!
userID
||
!
userPW
)
{
alert
(
"All blanks must be filled. Try agian."
);
}
else
{
loginApi
({
userID
:
userID
,
userPW
:
userPW
,
});
alert
(
"Successfully login!"
);
props
.
history
.
push
(
"/login"
);
}
};
return
(
<
div
className
=
{
classes
.
root
}
>
<
Paper
className
=
{
classes
.
paper
}
elevation
=
{
3
}
>
...
...
@@ -85,7 +110,7 @@ export default function LandingPage() {
setUserPW
(
e
.
target
.
value
);
}}
/
>
<
Button
className
=
{
classes
.
signin
}
variant
=
"outlined"
size
=
"small"
>
<
Button
className
=
{
classes
.
signin
}
variant
=
"outlined"
size
=
"small"
onClick
=
{
handleLogin
}
>
Login
<
/Button
>
<
div
className
=
{
classes
.
signup
}
>
...
...
server.js
View file @
54a78b9
...
...
@@ -8,7 +8,6 @@ const port = process.env.PORT || 5000;
const
bcrypt
=
require
(
"bcrypt"
);
const
saltRounds
=
10
;
const
data
=
fs
.
readFileSync
(
"./database.json"
);
const
conf
=
JSON
.
parse
(
data
);
const
mysql
=
require
(
"mysql"
);
...
...
@@ -98,7 +97,10 @@ app.post("/api/login", (req, res) => {
}
else
{
// console.log('The solution is: ', results);
if
(
results
.
length
>
0
)
{
if
(
results
[
0
].
userID
==
password
)
{
bcrypt
.
compare
(
enteredPW
,
results
[
0
].
userPW
,
function
(
err
,
check
)
{
console
.
log
(
check
);
if
(
check
)
{
console
.
log
(
"sec"
)
res
.
send
({
"code"
:
200
,
"success"
:
"login sucessfull"
...
...
@@ -106,9 +108,10 @@ app.post("/api/login", (req, res) => {
}
else
{
res
.
send
({
"code"
:
204
,
"success"
:
"
Email and password does not match
"
"success"
:
"
id and password does not match.
"
});
}
});
}
else
{
res
.
send
({
"code"
:
204
,
...
...
@@ -117,6 +120,5 @@ app.post("/api/login", (req, res) => {
}
}
})
}
});
app
.
listen
(
port
,
()
=>
console
.
log
(
`Listening on port
${
port
}
`
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment