Showing
3 changed files
with
40 additions
and
23 deletions
... | @@ -36,7 +36,6 @@ const SigninPage = (props) => { | ... | @@ -36,7 +36,6 @@ const SigninPage = (props) => { |
36 | cookie.save('username', response.username, { | 36 | cookie.save('username', response.username, { |
37 | expires | 37 | expires |
38 | }) | 38 | }) |
39 | - alert('Login success'); | ||
40 | props.history.push('/mypick'); | 39 | props.history.push('/mypick'); |
41 | } else if(response.message === "user does not exist"){ | 40 | } else if(response.message === "user does not exist"){ |
42 | alert('User does not exist'); | 41 | alert('User does not exist'); | ... | ... |
... | @@ -37,12 +37,18 @@ const SigninPage = (props) => { | ... | @@ -37,12 +37,18 @@ const SigninPage = (props) => { |
37 | fetch("http://localhost:3000/api/signup", signup_info) | 37 | fetch("http://localhost:3000/api/signup", signup_info) |
38 | .then(response => response.json()) | 38 | .then(response => response.json()) |
39 | .then(json => { | 39 | .then(json => { |
40 | - if(json.code === 200) { | 40 | + if(json.message === 'success') { |
41 | alert('회원가입에 성공했습니다.'); | 41 | alert('회원가입에 성공했습니다.'); |
42 | props.history.push('/signin'); | 42 | props.history.push('/signin'); |
43 | - } | 43 | + } |
44 | - else if(json.code === 400) { | 44 | + else if(json.message === 'user exist') { |
45 | + alert('이미 존재하는 유저입니다'); | ||
46 | + setUsername(''); | ||
47 | + setPassword(''); | ||
48 | + } else { | ||
45 | alert('회원가입에 실패했습니다.'); | 49 | alert('회원가입에 실패했습니다.'); |
50 | + setUsername(''); | ||
51 | + setPassword(''); | ||
46 | } | 52 | } |
47 | }) | 53 | }) |
48 | } | 54 | } | ... | ... |
... | @@ -40,28 +40,40 @@ app.get("/api/datas", (req, res) => { | ... | @@ -40,28 +40,40 @@ app.get("/api/datas", (req, res) => { |
40 | res.send(iconv.decode(dataBuffer, "EUC-KR").toString()); | 40 | res.send(iconv.decode(dataBuffer, "EUC-KR").toString()); |
41 | }); | 41 | }); |
42 | 42 | ||
43 | -// ???? ???? ?? | ||
44 | // signup | 43 | // signup |
45 | app.post("/api/signup", (req, res) => { | 44 | app.post("/api/signup", (req, res) => { |
46 | - let sql = "INSERT INTO USER (name, pw) VALUES(?, ?)"; | 45 | + |
47 | - let plainPassword = req.body.password; | 46 | + let sql_usercheck = `SELECT * FROM USER WHERE name='${req.body.username}';`; |
48 | - bcrypt.hash(plainPassword, saltRounds, function (err, hash) { | 47 | + connection.query(sql_usercheck, (err, rows, fields) => { |
49 | - const params = [req.body.username, hash]; | 48 | + console.log(rows); |
50 | - connection.query(sql, params, (err, rows, fields) => { | 49 | + if(rows.length!==0) { |
51 | - if (err) { | 50 | + return res.json({ |
52 | - console.log(err); | 51 | + code: 400, |
53 | - res.send({ | 52 | + message: 'user exist' |
54 | - code: 400, | 53 | + }) |
55 | - message: "error", | 54 | + } |
56 | - }); | 55 | + else { |
57 | - } else { | 56 | + let sql = "INSERT INTO USER (name, pw) VALUES(?, ?)"; |
58 | - res.send({ | 57 | + let plainPassword = req.body.password; |
59 | - code: 200, | 58 | + bcrypt.hash(plainPassword, saltRounds, function (err, hash) { |
60 | - message: "success", | 59 | + const params = [req.body.username, hash]; |
60 | + connection.query(sql, params, (err, rows, fields) => { | ||
61 | + if (err) { | ||
62 | + console.log(err); | ||
63 | + res.send({ | ||
64 | + code: 400, | ||
65 | + message: "error", | ||
66 | + }); | ||
67 | + } else { | ||
68 | + res.send({ | ||
69 | + code: 200, | ||
70 | + message: "success", | ||
71 | + }); | ||
72 | + } | ||
61 | }); | 73 | }); |
62 | - } | 74 | + }); |
63 | - }); | 75 | + } |
64 | - }); | 76 | + }) |
65 | }); | 77 | }); |
66 | 78 | ||
67 | app.post("/api/signin", (req, res) => { | 79 | app.post("/api/signin", (req, res) => { | ... | ... |
-
Please register or login to post a comment