Showing
6 changed files
with
108 additions
and
19 deletions
... | @@ -75,7 +75,7 @@ export default function AddButton({ handleClose }) { | ... | @@ -75,7 +75,7 @@ export default function AddButton({ handleClose }) { |
75 | const [title, setTitle] = useState(""); | 75 | const [title, setTitle] = useState(""); |
76 | const [date, setDate] = useState(new Date()); | 76 | const [date, setDate] = useState(new Date()); |
77 | const [isPublic, setIsPublic] = useState(1); | 77 | const [isPublic, setIsPublic] = useState(1); |
78 | - const [textList, setTextList] = useState(new Array()); | 78 | + const [textList, setTextList] = useState([]); |
79 | const [textFieldBody, setTextFieldBody] = useState([ | 79 | const [textFieldBody, setTextFieldBody] = useState([ |
80 | <TextField required label="To do 1" onChange={(e) => handleText(e, 0)} />, | 80 | <TextField required label="To do 1" onChange={(e) => handleText(e, 0)} />, |
81 | ]); | 81 | ]); | ... | ... |
... | @@ -49,8 +49,8 @@ const useStyles = makeStyles((theme) => ({ | ... | @@ -49,8 +49,8 @@ const useStyles = makeStyles((theme) => ({ |
49 | width: "70%", | 49 | width: "70%", |
50 | }, | 50 | }, |
51 | signup: { | 51 | signup: { |
52 | - fontSize: 13, | ||
53 | top: "7.9rem", | 52 | top: "7.9rem", |
53 | + fontSize: 13, | ||
54 | }, | 54 | }, |
55 | })); | 55 | })); |
56 | 56 | ... | ... |
... | @@ -32,54 +32,96 @@ const useStyles = makeStyles((theme) => ({ | ... | @@ -32,54 +32,96 @@ const useStyles = makeStyles((theme) => ({ |
32 | }, | 32 | }, |
33 | title: { | 33 | title: { |
34 | width: "100%", | 34 | width: "100%", |
35 | - marginTop: "5rem", | 35 | + marginTop: "3.5rem", |
36 | fontSize: 40, | 36 | fontSize: 40, |
37 | textAlign: "center", | 37 | textAlign: "center", |
38 | }, | 38 | }, |
39 | idInput: { | 39 | idInput: { |
40 | - top: "3.5rem", | 40 | + top: "2rem", |
41 | + width: "70%", | ||
42 | + }, | ||
43 | + nameItput: { | ||
44 | + top: "3rem", | ||
41 | width: "70%", | 45 | width: "70%", |
42 | }, | 46 | }, |
43 | pwInput: { | 47 | pwInput: { |
44 | - top: "5.5rem", | 48 | + top: "4rem", |
49 | + width: "70%", | ||
50 | + }, | ||
51 | + pwCheck: { | ||
52 | + top: "5rem", | ||
45 | width: "70%", | 53 | width: "70%", |
46 | }, | 54 | }, |
47 | - signin: { | 55 | + submit: { |
48 | - top: "7.4rem", | 56 | + top: "6.5rem", |
49 | width: "70%", | 57 | width: "70%", |
50 | }, | 58 | }, |
51 | - signup: { | 59 | + login: { |
60 | + top: "7rem", | ||
52 | fontSize: 13, | 61 | fontSize: 13, |
53 | - top: "7.9rem", | ||
54 | }, | 62 | }, |
55 | })); | 63 | })); |
56 | 64 | ||
57 | -export default function LandingPage() { | 65 | +export default function LandingPage(props) { |
58 | const classes = useStyles(); | 66 | const classes = useStyles(); |
59 | 67 | ||
60 | const [userID, setUserID] = useState(); | 68 | const [userID, setUserID] = useState(); |
61 | - const [NickName, setNickName] = useState(); | 69 | + const [nickName, setNickName] = useState(); |
62 | const [userPW, setUserPW] = useState(); | 70 | const [userPW, setUserPW] = useState(); |
63 | const [checkPW, setCheckPW] = useState(); | 71 | const [checkPW, setCheckPW] = useState(); |
72 | + const [matchPW, setMatchPW] = useState(false); | ||
73 | + | ||
74 | + const signUpApi = (data) => { | ||
75 | + return fetch("/api/signup", { | ||
76 | + method: "POST", | ||
77 | + headers: { | ||
78 | + "Content-Type": "application/json", | ||
79 | + }, | ||
80 | + body: JSON.stringify(data), | ||
81 | + }).then((response) => response.json()); | ||
82 | + }; | ||
83 | + | ||
84 | + const handleSubmit = () => { | ||
85 | + if (!userID || !nickName || !userPW || !checkPW) { | ||
86 | + alert("All blanks must be filled. Try agian."); | ||
87 | + }else if (matchPW === true){ | ||
88 | + alert("Passwords do not match."); | ||
89 | + } | ||
90 | + else { | ||
91 | + signUpApi({ | ||
92 | + userID: userID, | ||
93 | + userPW: userPW, | ||
94 | + userName: nickName, | ||
95 | + }); | ||
96 | + alert("Successfully registered!"); | ||
97 | + props.history.push("/login"); | ||
98 | + } | ||
99 | + }; | ||
64 | 100 | ||
65 | return ( | 101 | return ( |
66 | <div className={classes.root}> | 102 | <div className={classes.root}> |
67 | <Paper className={classes.paper} elevation={3}> | 103 | <Paper className={classes.paper} elevation={3}> |
68 | <Grid container className={classes.grid}> | 104 | <Grid container className={classes.grid}> |
69 | - <div className={classes.title}>SIGN IN</div> | 105 | + <div className={classes.title}>SIGN UP</div> |
70 | <TextField | 106 | <TextField |
71 | required | 107 | required |
72 | className={classes.idInput} | 108 | className={classes.idInput} |
73 | label="ID" | 109 | label="ID" |
74 | variant="outlined" | 110 | variant="outlined" |
75 | size="small" | 111 | size="small" |
112 | + onChange={(e) => { | ||
113 | + setUserID(e.target.value); | ||
114 | + }} | ||
76 | /> | 115 | /> |
77 | <TextField | 116 | <TextField |
78 | required | 117 | required |
79 | - className={classes.idInput} | 118 | + className={classes.nameItput} |
80 | - label="ID" | 119 | + label="NickName" |
81 | variant="outlined" | 120 | variant="outlined" |
82 | size="small" | 121 | size="small" |
122 | + onChange={(e) => { | ||
123 | + setNickName(e.target.value); | ||
124 | + }} | ||
83 | /> | 125 | /> |
84 | <TextField | 126 | <TextField |
85 | required | 127 | required |
... | @@ -89,20 +131,42 @@ export default function LandingPage() { | ... | @@ -89,20 +131,42 @@ export default function LandingPage() { |
89 | autoComplete="current-password" | 131 | autoComplete="current-password" |
90 | variant="outlined" | 132 | variant="outlined" |
91 | size="small" | 133 | size="small" |
134 | + onChange={(e) => { | ||
135 | + setUserPW(e.target.value); | ||
136 | + }} | ||
92 | /> | 137 | /> |
93 | <TextField | 138 | <TextField |
94 | required | 139 | required |
95 | - className={classes.pwInput} | 140 | + error={matchPW} |
96 | - label="Password" | 141 | + className={classes.pwCheck} |
142 | + label="Re-enter Password" | ||
97 | type="password" | 143 | type="password" |
98 | autoComplete="current-password" | 144 | autoComplete="current-password" |
99 | variant="outlined" | 145 | variant="outlined" |
100 | size="small" | 146 | size="small" |
147 | + onChange={(e) => { | ||
148 | + const value = e.target.value; | ||
149 | + setCheckPW(value); | ||
150 | + if (value !== userPW) { | ||
151 | + setMatchPW(true); | ||
152 | + } else { | ||
153 | + setMatchPW(false); | ||
154 | + } | ||
155 | + }} | ||
101 | /> | 156 | /> |
102 | - <Button className={classes.signin} variant="outlined" size="small"> | 157 | + <Button |
103 | - Login | 158 | + className={classes.submit} |
159 | + variant="outlined" | ||
160 | + size="small" | ||
161 | + onClick={handleSubmit} | ||
162 | + > | ||
163 | + Submit | ||
104 | </Button> | 164 | </Button> |
105 | - <div className={classes.signup}>Click here to SIGN UP</div> | 165 | + <div className={classes.login}> |
166 | + <Link to="/login" style={{ color: "gray", textDecoration: "none" }}> | ||
167 | + Click here to return to the login page | ||
168 | + </Link> | ||
169 | + </div> | ||
106 | </Grid> | 170 | </Grid> |
107 | </Paper> | 171 | </Paper> |
108 | </div> | 172 | </div> | ... | ... |
... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
7 | "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"" | 7 | "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"" |
8 | }, | 8 | }, |
9 | "dependencies": { | 9 | "dependencies": { |
10 | + "bcrypt": "^5.0.0", | ||
10 | "body-parser": "^1.18.3", | 11 | "body-parser": "^1.18.3", |
11 | "express": "^4.16.4", | 12 | "express": "^4.16.4", |
12 | "mysql": "^2.18.1" | 13 | "mysql": "^2.18.1" | ... | ... |
... | @@ -5,6 +5,9 @@ const app = express(); | ... | @@ -5,6 +5,9 @@ const app = express(); |
5 | 5 | ||
6 | const port = process.env.PORT || 5000; | 6 | const port = process.env.PORT || 5000; |
7 | 7 | ||
8 | +const bcrypt = require('bcrypt'); | ||
9 | +const saltRounds = 10; | ||
10 | + | ||
8 | const data = fs.readFileSync("./database.json"); | 11 | const data = fs.readFileSync("./database.json"); |
9 | const conf = JSON.parse(data); | 12 | const conf = JSON.parse(data); |
10 | const mysql = require("mysql"); | 13 | const mysql = require("mysql"); |
... | @@ -47,4 +50,25 @@ app.post("/api/addcard", (req, res) => { | ... | @@ -47,4 +50,25 @@ app.post("/api/addcard", (req, res) => { |
47 | }); | 50 | }); |
48 | }); | 51 | }); |
49 | 52 | ||
53 | +app.post("/api/signup", (req, res) => { | ||
54 | + const data = req.body; | ||
55 | + | ||
56 | + console.log(data); | ||
57 | + const sql = "INSERT INTO USERINFO(userID,userPW,userName) VALUES(?,?,?);"; | ||
58 | + const params =[data.userID,data.userPW,data.userName]; | ||
59 | + connection.query(sql, params, (err, rows, fields) => { | ||
60 | + if (err) { | ||
61 | + res.send({ | ||
62 | + code: 400, | ||
63 | + message: "error", | ||
64 | + }); | ||
65 | + } else { | ||
66 | + res.send({ | ||
67 | + code: 200, | ||
68 | + message: "success", | ||
69 | + }); | ||
70 | + } | ||
71 | + }); | ||
72 | +}); | ||
73 | + | ||
50 | app.listen(port, () => console.log(`Listening on port ${port}`)); | 74 | app.listen(port, () => console.log(`Listening on port ${port}`)); | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment