Showing
12 changed files
with
426 additions
and
107 deletions
| ... | @@ -11,7 +11,7 @@ | ... | @@ -11,7 +11,7 @@ |
| 11 | "react": "^16.13.1", | 11 | "react": "^16.13.1", |
| 12 | "react-dom": "^16.13.1", | 12 | "react-dom": "^16.13.1", |
| 13 | "react-router-dom": "^5.2.0", | 13 | "react-router-dom": "^5.2.0", |
| 14 | - "react-scripts": "3.4.1" | 14 | + "react-scripts": "^3.4.1" |
| 15 | }, | 15 | }, |
| 16 | "scripts": { | 16 | "scripts": { |
| 17 | "start": "react-scripts start", | 17 | "start": "react-scripts start", | ... | ... |
| ... | @@ -73,8 +73,7 @@ export default function BodyLayout() { | ... | @@ -73,8 +73,7 @@ export default function BodyLayout() { |
| 73 | {data.map((card, idx) => { | 73 | {data.map((card, idx) => { |
| 74 | let isVisible = card.isPublic; | 74 | let isVisible = card.isPublic; |
| 75 | let showDate = null; | 75 | let showDate = null; |
| 76 | - const isMine = card.name === "aa"; ////data.name과 session name 비교 로그인 구현하고 수정 | 76 | + const isMine = card.name === localStorage["userName"]; //remove item |
| 77 | - | ||
| 78 | if (idx === 0 || card.date !== data[idx - 1].date) { | 77 | if (idx === 0 || card.date !== data[idx - 1].date) { |
| 79 | showDate = ( | 78 | showDate = ( |
| 80 | <Typography variant="h4" className={classes.date}> | 79 | <Typography variant="h4" className={classes.date}> |
| ... | @@ -105,10 +104,6 @@ export default function BodyLayout() { | ... | @@ -105,10 +104,6 @@ export default function BodyLayout() { |
| 105 | return <>{showDate}</>; | 104 | return <>{showDate}</>; |
| 106 | } | 105 | } |
| 107 | })} | 106 | })} |
| 108 | - | ||
| 109 | - {/* <Grid item xs={6} sm={6} md={3}> | ||
| 110 | - <Icon style={{ fontSize: 60 }}>add_circle</Icon> | ||
| 111 | - </Grid> */} | ||
| 112 | </Grid> | 107 | </Grid> |
| 113 | <AddButton></AddButton> | 108 | <AddButton></AddButton> |
| 114 | </Container> | 109 | </Container> | ... | ... |
| ... | @@ -99,7 +99,7 @@ export default function AddButton({ handleClose }) { | ... | @@ -99,7 +99,7 @@ export default function AddButton({ handleClose }) { |
| 99 | const initCK = Array.apply(null, Array(textList.length)).map(Number.prototype.valueOf,0); | 99 | const initCK = Array.apply(null, Array(textList.length)).map(Number.prototype.valueOf,0); |
| 100 | addApi({ | 100 | addApi({ |
| 101 | isPublic: isPublic, | 101 | isPublic: isPublic, |
| 102 | - name: "testName", | 102 | + name: localStorage["userName"], |
| 103 | date: date.toLocaleDateString(), | 103 | date: date.toLocaleDateString(), |
| 104 | time: date.toLocaleTimeString(), | 104 | time: date.toLocaleTimeString(), |
| 105 | title: title, | 105 | title: title, | ... | ... |
client/src/components/ModifyControl.js
0 → 100644
| 1 | +import React, { useState } from "react"; | ||
| 2 | + | ||
| 3 | +import { makeStyles } from "@material-ui/core/styles"; | ||
| 4 | + | ||
| 5 | +import Modal from "@material-ui/core/Modal"; | ||
| 6 | +import IconButton from "@material-ui/core/IconButton"; | ||
| 7 | +import TextField from "@material-ui/core/TextField"; | ||
| 8 | +import Button from "@material-ui/core/Button"; | ||
| 9 | +import Typography from "@material-ui/core/Typography"; | ||
| 10 | +import AddIcon from "@material-ui/icons/Add"; | ||
| 11 | +import FormControlLabel from "@material-ui/core/FormControlLabel"; | ||
| 12 | +import Checkbox from "@material-ui/core/Checkbox"; | ||
| 13 | + | ||
| 14 | +const useStyles = makeStyles((theme) => ({ | ||
| 15 | + iconButton: { | ||
| 16 | + margin: "0", | ||
| 17 | + padding: "0", | ||
| 18 | + position: "fixed", | ||
| 19 | + bottom: "3rem", | ||
| 20 | + right: "3rem", | ||
| 21 | + }, | ||
| 22 | + icon: { | ||
| 23 | + fontSize: 70, | ||
| 24 | + color: "black", | ||
| 25 | + }, | ||
| 26 | + addButton: { | ||
| 27 | + fontSize: 11, | ||
| 28 | + float: "right", | ||
| 29 | + margin: 0, | ||
| 30 | + marginTop: "1rem", | ||
| 31 | + marginRight: "1rem", | ||
| 32 | + }, | ||
| 33 | + buttonGroup: { | ||
| 34 | + clear: "both", | ||
| 35 | + "& > *": { | ||
| 36 | + margin: theme.spacing(1), | ||
| 37 | + float: "right", | ||
| 38 | + }, | ||
| 39 | + }, | ||
| 40 | + title: { | ||
| 41 | + float: "left", | ||
| 42 | + width: "13rem", | ||
| 43 | + marginLeft: "0.5rem", | ||
| 44 | + marginTop: "0.3rem", | ||
| 45 | + padding: 0, | ||
| 46 | + }, | ||
| 47 | + isPublic: { | ||
| 48 | + float: "left", | ||
| 49 | + }, | ||
| 50 | + paper: { | ||
| 51 | + top: "50%", | ||
| 52 | + left: "50%", | ||
| 53 | + transform: "translate(-50%, -50%)", | ||
| 54 | + position: "absolute", | ||
| 55 | + width: "90%", | ||
| 56 | + maxWidth: 320, | ||
| 57 | + maxHeight: 500, | ||
| 58 | + msOverflowStyle: "none", | ||
| 59 | + backgroundColor: "white", | ||
| 60 | + boxShadow: theme.shadows[5], | ||
| 61 | + padding: theme.spacing(2, 4, 2), | ||
| 62 | + }, | ||
| 63 | + input: { | ||
| 64 | + "& > *": { | ||
| 65 | + float: "left", | ||
| 66 | + margin: theme.spacing(1), | ||
| 67 | + marginRight: 0, | ||
| 68 | + width: "14.5rem", | ||
| 69 | + }, | ||
| 70 | + }, | ||
| 71 | +})); | ||
| 72 | + | ||
| 73 | +export default function AddButton({ data, handleClose }) { | ||
| 74 | + const classes = useStyles(); | ||
| 75 | + const [title, setTitle] = useState(data.title); | ||
| 76 | + //const [date, setDate] = useState(new Date()); | ||
| 77 | + const [isPublic, setIsPublic] = useState(data.isPublic); | ||
| 78 | + const [textList, setTextList] = useState(data.todo.split(",")); | ||
| 79 | + const [textFieldBody, setTextFieldBody] = useState( | ||
| 80 | + textList.map((text, idx) => { | ||
| 81 | + return ( | ||
| 82 | + <TextField | ||
| 83 | + required | ||
| 84 | + fullWidth={true} | ||
| 85 | + defaultValue={textList[idx]} | ||
| 86 | + label={"To do " + (idx + 1)} | ||
| 87 | + onChange={(e) => handleText(e, idx)} | ||
| 88 | + /> | ||
| 89 | + ); | ||
| 90 | + }) | ||
| 91 | + ); | ||
| 92 | + | ||
| 93 | + const modifyApi = (data) => { | ||
| 94 | + return fetch("/api/updatecard", { | ||
| 95 | + method: "PUT", | ||
| 96 | + headers: { | ||
| 97 | + "Content-Type": "application/json", | ||
| 98 | + }, | ||
| 99 | + body: JSON.stringify(data), | ||
| 100 | + }).then((response) => response.json()); | ||
| 101 | + }; | ||
| 102 | + | ||
| 103 | + const checkAndClose = () => { | ||
| 104 | + if (title === "") { | ||
| 105 | + alert("Please enter a title!"); | ||
| 106 | + } else if (checkEemptyList(textList)) { | ||
| 107 | + alert("Please fill in the blank!"); | ||
| 108 | + } else { | ||
| 109 | + const initCK = Array.apply(null, Array(textList.length)).map( | ||
| 110 | + Number.prototype.valueOf, | ||
| 111 | + 0 | ||
| 112 | + ); | ||
| 113 | + modifyApi({ | ||
| 114 | + isPublic: isPublic, | ||
| 115 | + name: localStorage["userName"], | ||
| 116 | + date: data.date, | ||
| 117 | + time: data.time, | ||
| 118 | + title: title, | ||
| 119 | + todo: textList.join(","), | ||
| 120 | + ck: initCK.join(","), | ||
| 121 | + }); | ||
| 122 | + handleClose(); | ||
| 123 | + } | ||
| 124 | + }; | ||
| 125 | + | ||
| 126 | + const checkEemptyList = (arr) => { | ||
| 127 | + if (arr.length === 0) { | ||
| 128 | + return 1; | ||
| 129 | + } | ||
| 130 | + for (let idx = 0; idx < arr.length; idx++) { | ||
| 131 | + if (arr[idx] === undefined || arr[idx] === "") { | ||
| 132 | + return 1; | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + return 0; | ||
| 136 | + }; | ||
| 137 | + | ||
| 138 | + const handleTitle = (e) => { | ||
| 139 | + setTitle(e.target.value); | ||
| 140 | + }; | ||
| 141 | + | ||
| 142 | + const handlePublic = () => { | ||
| 143 | + setIsPublic(isPublic ? 0 : 1); | ||
| 144 | + }; | ||
| 145 | + | ||
| 146 | + const handleText = (e, idx) => { | ||
| 147 | + let tempArr = textList; | ||
| 148 | + tempArr[idx] = e.target.value; | ||
| 149 | + setTextList(tempArr); | ||
| 150 | + }; | ||
| 151 | + | ||
| 152 | + const handleAdd = () => { | ||
| 153 | + if (textFieldBody.length < 5) { | ||
| 154 | + const idx = textFieldBody.length; | ||
| 155 | + setTextFieldBody([ | ||
| 156 | + ...textFieldBody, | ||
| 157 | + <TextField | ||
| 158 | + required | ||
| 159 | + label={"To do " + (idx + 1)} | ||
| 160 | + onChange={(e) => handleText(e, idx)} | ||
| 161 | + />, | ||
| 162 | + ]); | ||
| 163 | + } else { | ||
| 164 | + alert("You can register up to five."); | ||
| 165 | + } | ||
| 166 | + }; | ||
| 167 | + | ||
| 168 | + return ( | ||
| 169 | + <> | ||
| 170 | + <Modal open={true}> | ||
| 171 | + <div className={classes.paper}> | ||
| 172 | + <Typography className={classes.title} variant="h5"> | ||
| 173 | + MODIFY TODO | ||
| 174 | + </Typography> | ||
| 175 | + <FormControlLabel | ||
| 176 | + className={classes.isPublic} | ||
| 177 | + control={<Checkbox onClick={handlePublic} />} | ||
| 178 | + checked={isPublic} | ||
| 179 | + label="Public" | ||
| 180 | + /> | ||
| 181 | + | ||
| 182 | + <form className={classes.input} noValidate autoComplete="off"> | ||
| 183 | + <TextField required label="Title" onChange={handleTitle} defaultValue={data.title}/> | ||
| 184 | + {textFieldBody.map((field) => field)} | ||
| 185 | + </form> | ||
| 186 | + <IconButton className={classes.addButton} onClick={handleAdd}> | ||
| 187 | + <AddIcon /> | ||
| 188 | + </IconButton> | ||
| 189 | + | ||
| 190 | + <form className={classes.buttonGroup}> | ||
| 191 | + <Button variant="contained" color="primary" onClick={checkAndClose}> | ||
| 192 | + 수정 | ||
| 193 | + </Button> | ||
| 194 | + <Button variant="contained" color="secondary" onClick={handleClose}> | ||
| 195 | + 삭제 | ||
| 196 | + </Button> | ||
| 197 | + </form> | ||
| 198 | + </div> | ||
| 199 | + </Modal> | ||
| 200 | + </> | ||
| 201 | + ); | ||
| 202 | +} |
| ... | @@ -4,8 +4,6 @@ import AppBar from '@material-ui/core/AppBar'; | ... | @@ -4,8 +4,6 @@ import AppBar from '@material-ui/core/AppBar'; |
| 4 | import Toolbar from '@material-ui/core/Toolbar'; | 4 | import Toolbar from '@material-ui/core/Toolbar'; |
| 5 | import Typography from '@material-ui/core/Typography'; | 5 | import Typography from '@material-ui/core/Typography'; |
| 6 | import Button from '@material-ui/core/Button'; | 6 | import Button from '@material-ui/core/Button'; |
| 7 | -import IconButton from '@material-ui/core/IconButton'; | ||
| 8 | -import MenuIcon from '@material-ui/icons/Menu'; | ||
| 9 | 7 | ||
| 10 | const useStyles = makeStyles((theme) => ({ | 8 | const useStyles = makeStyles((theme) => ({ |
| 11 | root: { | 9 | root: { |
| ... | @@ -14,12 +12,13 @@ const useStyles = makeStyles((theme) => ({ | ... | @@ -14,12 +12,13 @@ const useStyles = makeStyles((theme) => ({ |
| 14 | bar:{ | 12 | bar:{ |
| 15 | backgroundColor:"rgba(0,0,0,0.8)" | 13 | backgroundColor:"rgba(0,0,0,0.8)" |
| 16 | }, | 14 | }, |
| 17 | - menuButton: { | ||
| 18 | - marginRight: theme.spacing(2), | ||
| 19 | - }, | ||
| 20 | title: { | 15 | title: { |
| 16 | + marginLeft:"9%", | ||
| 21 | flexGrow: 1, | 17 | flexGrow: 1, |
| 22 | }, | 18 | }, |
| 19 | + logout:{ | ||
| 20 | + marginRight:"9%", | ||
| 21 | + } | ||
| 23 | })); | 22 | })); |
| 24 | 23 | ||
| 25 | export default function ButtonAppBar() { | 24 | export default function ButtonAppBar() { |
| ... | @@ -29,13 +28,10 @@ export default function ButtonAppBar() { | ... | @@ -29,13 +28,10 @@ export default function ButtonAppBar() { |
| 29 | <div className={classes.root}> | 28 | <div className={classes.root}> |
| 30 | <AppBar className={classes.bar} position="fixed"> | 29 | <AppBar className={classes.bar} position="fixed"> |
| 31 | <Toolbar> | 30 | <Toolbar> |
| 32 | - <IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="menu"> | ||
| 33 | - <MenuIcon /> | ||
| 34 | - </IconButton> | ||
| 35 | <Typography variant="h6" className={classes.title}> | 31 | <Typography variant="h6" className={classes.title}> |
| 36 | Do-gether | 32 | Do-gether |
| 37 | </Typography> | 33 | </Typography> |
| 38 | - <Button color="inherit">Logout</Button> | 34 | + <Button color="inherit" className={classes.logout}>Logout</Button> |
| 39 | </Toolbar> | 35 | </Toolbar> |
| 40 | </AppBar> | 36 | </AppBar> |
| 41 | </div> | 37 | </div> | ... | ... |
| 1 | -import React from "react"; | 1 | +import React, { useState } from "react"; |
| 2 | +import ModifyControl from "./ModifyControl.js"; | ||
| 2 | 3 | ||
| 3 | import { makeStyles } from "@material-ui/core/styles"; | 4 | import { makeStyles } from "@material-ui/core/styles"; |
| 4 | - | ||
| 5 | import Icon from "@material-ui/core/Icon"; | 5 | import Icon from "@material-ui/core/Icon"; |
| 6 | import IconButton from "@material-ui/core/IconButton"; | 6 | import IconButton from "@material-ui/core/IconButton"; |
| 7 | 7 | ||
| ... | @@ -17,16 +17,35 @@ const useStyles = makeStyles({ | ... | @@ -17,16 +17,35 @@ const useStyles = makeStyles({ |
| 17 | }, | 17 | }, |
| 18 | }); | 18 | }); |
| 19 | 19 | ||
| 20 | -export default function SettingButton() { | 20 | +export default function SettingButton({data, isMine }) { |
| 21 | const classes = useStyles(); | 21 | const classes = useStyles(); |
| 22 | + const [open, setOpen] = useState(); | ||
| 23 | + | ||
| 24 | + const handleOpen = () => { | ||
| 25 | + setOpen(true); | ||
| 26 | + }; | ||
| 27 | + | ||
| 28 | + const handleClose = () => { | ||
| 29 | + setOpen(false); | ||
| 30 | + }; | ||
| 22 | 31 | ||
| 23 | - return ( | 32 | + if (isMine) { |
| 24 | - <> | 33 | + if (!open) { |
| 25 | - <IconButton className={classes.iconButton}> | 34 | + return ( |
| 26 | - <Icon className={classes.icon}> | 35 | + <> |
| 27 | - settings | 36 | + <IconButton className={classes.iconButton} onClick={handleOpen}> |
| 28 | - </Icon> | 37 | + <Icon className={classes.icon}>settings</Icon> |
| 29 | - </IconButton> | 38 | + </IconButton> |
| 30 | - </> | 39 | + </> |
| 31 | - ); | 40 | + ); |
| 41 | + } else { | ||
| 42 | + return ( | ||
| 43 | + <> | ||
| 44 | + <ModifyControl handleClose={handleClose} data={data}/> | ||
| 45 | + </> | ||
| 46 | + ); | ||
| 47 | + } | ||
| 48 | + } else { | ||
| 49 | + return <></>; | ||
| 50 | + } | ||
| 32 | } | 51 | } | ... | ... |
| 1 | -import React, {useState} from "react"; | 1 | +import React, { useState } from "react"; |
| 2 | import { makeStyles } from "@material-ui/core/styles"; | 2 | import { makeStyles } from "@material-ui/core/styles"; |
| 3 | import Card from "@material-ui/core/Card"; | 3 | import Card from "@material-ui/core/Card"; |
| 4 | import CardContent from "@material-ui/core/CardContent"; | 4 | import CardContent from "@material-ui/core/CardContent"; |
| ... | @@ -30,58 +30,82 @@ const useStyles = makeStyles({ | ... | @@ -30,58 +30,82 @@ const useStyles = makeStyles({ |
| 30 | }, | 30 | }, |
| 31 | }); | 31 | }); |
| 32 | 32 | ||
| 33 | - | 33 | +export default function TodoCard({ data, isMine }) { |
| 34 | -export default function TodoCard({ data, isMine}) { | ||
| 35 | const classes = useStyles(); | 34 | const classes = useStyles(); |
| 35 | + const [open, setOpen] = useState(false); | ||
| 36 | const [render, setRender] = useState(0); | 36 | const [render, setRender] = useState(0); |
| 37 | - const todo = data.todo.split(",").map((text)=>{ | 37 | + const todo = data.todo.split(",").map((text) => { |
| 38 | - return text; | 38 | + return text; |
| 39 | }); | 39 | }); |
| 40 | - const [checkState, setCheckState] = useState(data.ck.split(",").map((ck) => { | 40 | + const [checkState, setCheckState] = useState( |
| 41 | + data.ck.split(",").map((ck) => { | ||
| 41 | return parseInt(ck); | 42 | return parseInt(ck); |
| 42 | - })) | 43 | + }) |
| 43 | - let settingButton = null; | 44 | + ); |
| 44 | 45 | ||
| 45 | const handleCheck = (idx) => { | 46 | const handleCheck = (idx) => { |
| 46 | - let tempArr = checkState; | 47 | + if(localStorage["userName"]===data.name) |
| 47 | - tempArr[idx] = tempArr[idx]?0:1; | 48 | + { |
| 49 | + let tempArr = checkState; | ||
| 50 | + tempArr[idx] = tempArr[idx] ? 0 : 1; | ||
| 48 | setCheckState(tempArr); | 51 | setCheckState(tempArr); |
| 49 | setRender([]); | 52 | setRender([]); |
| 53 | + modifyApi({ | ||
| 54 | + isPublic: data.isPublic, | ||
| 55 | + name: localStorage["userName"], | ||
| 56 | + date: data.date, | ||
| 57 | + time: data.time, | ||
| 58 | + title: data.title, | ||
| 59 | + todo: data.todo, | ||
| 60 | + ck: tempArr.join(",") | ||
| 61 | + }); | ||
| 62 | + | ||
| 63 | + }else{ | ||
| 64 | + alert("You can't modify other people's list."); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + | ||
| 50 | }; | 68 | }; |
| 51 | 69 | ||
| 70 | + const modifyApi = (data) => { | ||
| 71 | + return fetch("/api/updatecard", { | ||
| 72 | + method: "PUT", | ||
| 73 | + headers: { | ||
| 74 | + "Content-Type": "application/json", | ||
| 75 | + }, | ||
| 76 | + body: JSON.stringify(data), | ||
| 77 | + }).then((response) => response.json()); | ||
| 78 | + }; | ||
| 52 | 79 | ||
| 53 | - if (isMine) { | ||
| 54 | - settingButton = ( | ||
| 55 | - <SettingButton></SettingButton> | ||
| 56 | - ); | ||
| 57 | - } | ||
| 58 | return ( | 80 | return ( |
| 59 | - <Card className={classes.root}> | 81 | + <> |
| 60 | - <CardContent> | 82 | + <Card className={classes.root}> |
| 61 | - <Typography className={classes.date} gutterBottom> {/*color="textSecondary"*/} | 83 | + <CardContent> |
| 62 | - {data.name} · {data.time} | 84 | + <Typography className={classes.date} gutterBottom> |
| 63 | - </Typography> | 85 | + {" "} |
| 64 | - | 86 | + {data.name} · {data.time} |
| 65 | - {settingButton} | 87 | + </Typography> |
| 66 | 88 | ||
| 67 | - <Typography className={classes.title} variant="h6"> | 89 | + <SettingButton isMine={isMine} data={data}></SettingButton> |
| 68 | - {data.title} | ||
| 69 | - </Typography> | ||
| 70 | - <Typography className={classes.percent} variant="h6"> | ||
| 71 | 90 | ||
| 72 | - {checkState.reduce((a, b) => a + b)}/{checkState.length} | 91 | + <Typography className={classes.title} variant="h6"> |
| 73 | - </Typography> | 92 | + {data.title} |
| 74 | - {todo.map((item, idx) => { | 93 | + </Typography> |
| 75 | - return ( | 94 | + <Typography className={classes.percent} variant="h6"> |
| 76 | - <FormControlLabel | 95 | + {checkState.reduce((a, b) => a + b)}/{checkState.length} |
| 77 | - className={classes.checkBox} | 96 | + </Typography> |
| 78 | - control={<Checkbox onClick={e=>(handleCheck(idx))}/>} | 97 | + {todo.map((item, idx) => { |
| 79 | - checked={checkState[idx]} | 98 | + return ( |
| 80 | - label={item} | 99 | + <FormControlLabel |
| 81 | - /> | 100 | + className={classes.checkBox} |
| 82 | - ); | 101 | + control={<Checkbox onClick={(e) => handleCheck(idx)} />} |
| 83 | - })} | 102 | + checked={checkState[idx]} |
| 84 | - </CardContent> | 103 | + label={item} |
| 85 | - </Card> | 104 | + /> |
| 105 | + ); | ||
| 106 | + })} | ||
| 107 | + </CardContent> | ||
| 108 | + </Card> | ||
| 109 | + </> | ||
| 86 | ); | 110 | ); |
| 87 | } | 111 | } | ... | ... |
| ... | @@ -68,7 +68,14 @@ export default function LandingPage(props) { | ... | @@ -68,7 +68,14 @@ export default function LandingPage(props) { |
| 68 | "Content-Type": "application/json", | 68 | "Content-Type": "application/json", |
| 69 | }, | 69 | }, |
| 70 | body: JSON.stringify(data), | 70 | body: JSON.stringify(data), |
| 71 | - }).then((response) => response.json()); | 71 | + }).then((response) => response.json()) |
| 72 | + .then(result => { | ||
| 73 | + if(result.success === 'login sucessfull') { | ||
| 74 | + localStorage.userName = result.username; | ||
| 75 | + window.location.href = '/main'; | ||
| 76 | + | ||
| 77 | + } | ||
| 78 | + }); | ||
| 72 | }; | 79 | }; |
| 73 | 80 | ||
| 74 | const handleLogin = () => { | 81 | const handleLogin = () => { | ... | ... |
| ... | @@ -9826,7 +9826,7 @@ react-router@5.2.0: | ... | @@ -9826,7 +9826,7 @@ react-router@5.2.0: |
| 9826 | tiny-invariant "^1.0.2" | 9826 | tiny-invariant "^1.0.2" |
| 9827 | tiny-warning "^1.0.0" | 9827 | tiny-warning "^1.0.0" |
| 9828 | 9828 | ||
| 9829 | -react-scripts@3.4.1: | 9829 | +react-scripts@^3.4.1: |
| 9830 | version "3.4.1" | 9830 | version "3.4.1" |
| 9831 | resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-3.4.1.tgz#f551298b5c71985cc491b9acf3c8e8c0ae3ada0a" | 9831 | resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-3.4.1.tgz#f551298b5c71985cc491b9acf3c8e8c0ae3ada0a" |
| 9832 | integrity sha512-JpTdi/0Sfd31mZA6Ukx+lq5j1JoKItX7qqEK4OiACjVQletM1P38g49d9/D0yTxp9FrSF+xpJFStkGgKEIRjlQ== | 9832 | integrity sha512-JpTdi/0Sfd31mZA6Ukx+lq5j1JoKItX7qqEK4OiACjVQletM1P38g49d9/D0yTxp9FrSF+xpJFStkGgKEIRjlQ== | ... | ... |
| ... | @@ -10,9 +10,14 @@ | ... | @@ -10,9 +10,14 @@ |
| 10 | "bcrypt": "^5.0.0", | 10 | "bcrypt": "^5.0.0", |
| 11 | "body-parser": "^1.18.3", | 11 | "body-parser": "^1.18.3", |
| 12 | "express": "^4.16.4", | 12 | "express": "^4.16.4", |
| 13 | - "mysql": "^2.18.1" | 13 | + "express-session": "^1.17.1", |
| 14 | + "mysql": "^2.18.1", | ||
| 15 | + "nodemon": "^2.0.4" | ||
| 14 | }, | 16 | }, |
| 15 | "devDependencies": { | 17 | "devDependencies": { |
| 16 | "concurrently": "^4.0.1" | 18 | "concurrently": "^4.0.1" |
| 17 | - } | 19 | + }, |
| 20 | + "proxy": "http://localhost:3000/", | ||
| 21 | + | ||
| 22 | + "license": "UNLICENSED" | ||
| 18 | } | 23 | } | ... | ... |
| 1 | const fs = require("fs"); | 1 | const fs = require("fs"); |
| 2 | const express = require("express"); | 2 | const express = require("express"); |
| 3 | const bodyParser = require("body-parser"); | 3 | const bodyParser = require("body-parser"); |
| 4 | +const bcrypt = require("bcrypt"); | ||
| 5 | +const session = require("express-session"); | ||
| 4 | const app = express(); | 6 | const app = express(); |
| 5 | 7 | ||
| 6 | const port = process.env.PORT || 5000; | 8 | const port = process.env.PORT || 5000; |
| 7 | 9 | ||
| 8 | -const bcrypt = require("bcrypt"); | ||
| 9 | const saltRounds = 10; | 10 | const saltRounds = 10; |
| 10 | 11 | ||
| 11 | const data = fs.readFileSync("./database.json"); | 12 | const data = fs.readFileSync("./database.json"); |
| ... | @@ -19,11 +20,17 @@ const connection = mysql.createConnection({ | ... | @@ -19,11 +20,17 @@ const connection = mysql.createConnection({ |
| 19 | port: conf.port, | 20 | port: conf.port, |
| 20 | database: conf.database, | 21 | database: conf.database, |
| 21 | }); | 22 | }); |
| 22 | - | ||
| 23 | connection.connect(); | 23 | connection.connect(); |
| 24 | 24 | ||
| 25 | app.use(bodyParser.json()); | 25 | app.use(bodyParser.json()); |
| 26 | app.use(bodyParser.urlencoded({ extended: true })); | 26 | app.use(bodyParser.urlencoded({ extended: true })); |
| 27 | +app.use( | ||
| 28 | + session({ | ||
| 29 | + secret: "asdjha!@#@#$dd", | ||
| 30 | + resave: false, | ||
| 31 | + saveUninitialized: true, | ||
| 32 | + }) | ||
| 33 | +); | ||
| 27 | 34 | ||
| 28 | app.get("/api/cards", (req, res) => { | 35 | app.get("/api/cards", (req, res) => { |
| 29 | connection.query("SELECT * FROM CARDINFO", (err, rows, fields) => { | 36 | connection.query("SELECT * FROM CARDINFO", (err, rows, fields) => { |
| ... | @@ -60,10 +67,68 @@ app.post("/api/addcard", (req, res) => { | ... | @@ -60,10 +67,68 @@ app.post("/api/addcard", (req, res) => { |
| 60 | }); | 67 | }); |
| 61 | }); | 68 | }); |
| 62 | 69 | ||
| 70 | +app.put("/api/updatecard", (req, res) => { | ||
| 71 | + const data = req.body; | ||
| 72 | + const sql = | ||
| 73 | + `UPDATE CARDINFO SET title="${data.title}",todo="${data.todo}",ck="${data.ck}" WHERE name="${data.name}" AND date="${data.date}" AND time="${data.time}";`; | ||
| 74 | + console.log(sql); | ||
| 75 | + // const params = [ | ||
| 76 | + // data.isPublic, | ||
| 77 | + // data.name, | ||
| 78 | + // data.date, | ||
| 79 | + // data.time, | ||
| 80 | + // data.title, | ||
| 81 | + // data.todo, | ||
| 82 | + // data.ck, | ||
| 83 | + // ]; | ||
| 84 | + connection.query(sql, (err, rows, fields) => { | ||
| 85 | + if (err) { | ||
| 86 | + res.send({ | ||
| 87 | + code: 400, | ||
| 88 | + message: "error", | ||
| 89 | + }); | ||
| 90 | + } else { | ||
| 91 | + res.send({ | ||
| 92 | + code: 200, | ||
| 93 | + message: "success", | ||
| 94 | + }); | ||
| 95 | + } | ||
| 96 | + }); | ||
| 97 | +}); | ||
| 98 | + | ||
| 99 | +app.delete("/api/deletecard", (req, res) => { | ||
| 100 | + const data = req.body; | ||
| 101 | + const sql = | ||
| 102 | + "INSERT INTO CARDINFO(isPublic,name,date,time,title,todo,ck) VALUES(?,?,?,?,?,?,?);"; | ||
| 103 | + | ||
| 104 | + const params = [ | ||
| 105 | + data.isPublic, | ||
| 106 | + data.name, | ||
| 107 | + data.date, | ||
| 108 | + data.time, | ||
| 109 | + data.title, | ||
| 110 | + data.todo, | ||
| 111 | + data.ck, | ||
| 112 | + ]; | ||
| 113 | + connection.query(sql, params, (err, rows, fields) => { | ||
| 114 | + if (err) { | ||
| 115 | + res.send({ | ||
| 116 | + code: 400, | ||
| 117 | + message: "error", | ||
| 118 | + }); | ||
| 119 | + } else { | ||
| 120 | + res.send({ | ||
| 121 | + code: 200, | ||
| 122 | + message: "success", | ||
| 123 | + }); | ||
| 124 | + } | ||
| 125 | + }); | ||
| 126 | +}); | ||
| 127 | + | ||
| 63 | app.post("/api/signup", async (req, res) => { | 128 | app.post("/api/signup", async (req, res) => { |
| 64 | const data = req.body; | 129 | const data = req.body; |
| 65 | const sql = "INSERT INTO USERINFO(userID,userPW,userName) VALUES(?,?,?);"; | 130 | const sql = "INSERT INTO USERINFO(userID,userPW,userName) VALUES(?,?,?);"; |
| 66 | - | 131 | + |
| 67 | await bcrypt.hash(data.userPW, saltRounds, function (err, hash) { | 132 | await bcrypt.hash(data.userPW, saltRounds, function (err, hash) { |
| 68 | let params = [data.userID, hash, data.userName]; | 133 | let params = [data.userID, hash, data.userName]; |
| 69 | connection.query(sql, params, (err, rows, fields) => { | 134 | connection.query(sql, params, (err, rows, fields) => { |
| ... | @@ -86,39 +151,45 @@ app.post("/api/login", (req, res) => { | ... | @@ -86,39 +151,45 @@ app.post("/api/login", (req, res) => { |
| 86 | const data = req.body; | 151 | const data = req.body; |
| 87 | const enteredID = data.userID; | 152 | const enteredID = data.userID; |
| 88 | const enteredPW = data.userPW; | 153 | const enteredPW = data.userPW; |
| 89 | - connection.query('SELECT * FROM USERINFO WHERE userID = ?', [enteredID], | 154 | + connection.query( |
| 90 | - function( error, results, fields) { | 155 | + "SELECT * FROM USERINFO WHERE userID = ?", |
| 156 | + [enteredID], | ||
| 157 | + function (error, results, fields) { | ||
| 91 | if (error) { | 158 | if (error) { |
| 92 | - // console.log("error ocurred", error); | 159 | + // console.log("error ocurred", error); |
| 93 | - res.send({ | 160 | + res.send({ |
| 94 | - "code": 400, | 161 | + code: 400, |
| 95 | - "failed": "error ocurred" | 162 | + failed: "error ocurred", |
| 96 | - }) | 163 | + }); |
| 97 | } else { | 164 | } else { |
| 98 | - // console.log('The solution is: ', results); | 165 | + // console.log('The solution is: ', results); |
| 99 | - if(results.length > 0) { | 166 | + if (results.length > 0) { |
| 100 | - bcrypt.compare(enteredPW, results[0].userPW, function(err, check) { | 167 | + bcrypt.compare(enteredPW, results[0].userPW, function (err, check) { |
| 101 | - console.log(check); | 168 | + console.log(check); |
| 102 | - if(check) { | 169 | + if (check) { |
| 103 | - console.log("sec") | 170 | + req.session.userName = results[0].userName; |
| 104 | - res.send({ | 171 | + console.log( req.session.userName); |
| 105 | - "code": 200, | 172 | + res.send({ |
| 106 | - "success": "login sucessfull" | 173 | + code: 200, |
| 107 | - }); | 174 | + success: "login sucessfull", |
| 108 | - } else { | 175 | + username : results[0].userName |
| 109 | - res.send({ | 176 | + }); |
| 110 | - "code": 204, | 177 | + // res.redirect("/main"); |
| 111 | - "success": "id and password does not match." | 178 | + } else { |
| 112 | - }); | ||
| 113 | - } | ||
| 114 | - }); | ||
| 115 | - } else { | ||
| 116 | res.send({ | 179 | res.send({ |
| 117 | - "code":204, | 180 | + code: 204, |
| 118 | - "success": "Email does not exists" | 181 | + success: "Id and password does not match.", |
| 119 | }); | 182 | }); |
| 120 | - } | 183 | + } |
| 121 | - } | 184 | + }); |
| 122 | - }) | 185 | + } else { |
| 186 | + res.send({ | ||
| 187 | + code: 204, | ||
| 188 | + success: "Id does not exists", | ||
| 189 | + }); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + ); | ||
| 123 | }); | 194 | }); |
| 124 | -app.listen(port, () => console.log(`Listening on port ${port}`)); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 195 | +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