swa07016

중복 가입 방지 구현

......@@ -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');
......
......@@ -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('');
}
})
}
......
......@@ -40,9 +40,19 @@ app.get("/api/datas", (req, res) => {
res.send(iconv.decode(dataBuffer, "EUC-KR").toString());
});
// ???? ???? ??
// signup
app.post("/api/signup", (req, res) => {
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) {
......@@ -62,6 +72,8 @@ app.post("/api/signup", (req, res) => {
}
});
});
}
})
});
app.post("/api/signin", (req, res) => {
......