김대휘

Session 로그인

...@@ -2,17 +2,20 @@ ...@@ -2,17 +2,20 @@
2 ---------- 2 ----------
3 Sharing your TODO-LIST with others!<br> 3 Sharing your TODO-LIST with others!<br>
4 Do-gether은 투두리스트를 다른사람들과 공유할 수 있도록 도와주는 동기부여 서비스입니다. 4 Do-gether은 투두리스트를 다른사람들과 공유할 수 있도록 도와주는 동기부여 서비스입니다.
5 +<br><br>
5 6
6 ## HOW TO USE 7 ## HOW TO USE
7 ----------------- 8 +----------
8 You can come here and use DO-GETHER.<br> 9 You can come here and use DO-GETHER.<br>
9 [`http://wwww.dogether.tk`](http://wwww.dogether.tk) 10 [`http://wwww.dogether.tk`](http://wwww.dogether.tk)
10 -![main](/uploads/0b44105f829a49b4211d4e6adc9d2c33/main.png) 11 +![main](/uploads/9dce27e61dc8a02f8fe0ab37dfaf4df5/main.png)
12 +<br><br>
11 13
12 ## HOW TO INSTALL 14 ## HOW TO INSTALL
13 -------------- 15 +---------
14 ### First, clone this project 16 ### First, clone this project
15 `git clone http://khuhub.khu.ac.kr/2019102153/Do-gether.git` 17 `git clone http://khuhub.khu.ac.kr/2019102153/Do-gether.git`
18 +<br><br>
16 19
17 and execute this command. 20 and execute this command.
18 ```sh 21 ```sh
...@@ -20,27 +23,29 @@ npm install ...@@ -20,27 +23,29 @@ npm install
20 cd client 23 cd client
21 npm install 24 npm install
22 ``` 25 ```
26 +<br><br>
23 27
24 - 28 +### Second, install YARN.
25 -### Second, install yarn.
26 On Debian or Ubuntu Linux, you can install Yarn via our Debian package repository. 29 On Debian or Ubuntu Linux, you can install Yarn via our Debian package repository.
30 +<br><br>
27 31
28 You will first need to configure the repository: 32 You will first need to configure the repository:
29 ```sh 33 ```sh
30 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - 34 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
31 echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list 35 echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
32 ``` 36 ```
37 +<br><br>
33 38
34 On Ubuntu 16.04 or below and Debian Stable,<br> 39 On Ubuntu 16.04 or below and Debian Stable,<br>
35 you will also need to configure the NodeSource repository to get a new enough version of Node.js. 40 you will also need to configure the NodeSource repository to get a new enough version of Node.js.
41 +<br><br>
36 42
37 Then you can simply: 43 Then you can simply:
38 -`sudo apt update && sudo apt install yarn` 44 +`sudo apt update && sudo apt install yarn`<br><br>
39 -
40 Reference from [`YARN`](https://yarnpkg.com/en/docs/install) 45 Reference from [`YARN`](https://yarnpkg.com/en/docs/install)
46 +<br><br>
41 47
42 - 48 +### Third, add "database.json"
43 -### Third, add [database.json]
44 you should add `database.json` in the following format. 49 you should add `database.json` in the following format.
45 ```sh 50 ```sh
46 { 51 {
...@@ -51,22 +56,28 @@ you should add `database.json` in the following format. ...@@ -51,22 +56,28 @@ you should add `database.json` in the following format.
51 "database":"table name" 56 "database":"table name"
52 } 57 }
53 ``` 58 ```
54 - 59 +<br><br>
55 60
56 ### Finally, you can use DOGETHER by using `yarn dev` in `Do-gether` directory. 61 ### Finally, you can use DOGETHER by using `yarn dev` in `Do-gether` directory.
57 - 62 +<br><br>
58 63
59 ### Error 64 ### Error
60 ----------- 65 +--------
61 In my case, an unknown error occurred when running `yarn dev`.<br> 66 In my case, an unknown error occurred when running `yarn dev`.<br>
62 So I solved it as follows. 67 So I solved it as follows.
63 - 68 +<br><br>
64 Execute this command. 69 Execute this command.
65 `vi Do-gether/client/node_modules/react-scripts/config/webpackDevServer.config.js` 70 `vi Do-gether/client/node_modules/react-scripts/config/webpackDevServer.config.js`
66 - 71 +<br><br>
67 And change the `disableHostCheck: ...` option to `disableHostCheck: true`. 72 And change the `disableHostCheck: ...` option to `disableHostCheck: true`.
68 ![error](/uploads/be3c1c269c2ee157825f6d9e143706fc/error.png) 73 ![error](/uploads/be3c1c269c2ee157825f6d9e143706fc/error.png)
74 +<br><br>
75 +
76 +## Presentation File
77 +You can check my presentation here.
78 +[2019102153_김대휘.pptx](/uploads/ec22aec2c186128329918ec641a54f73/2019102153_김대휘.pptx)
79 +<br><br>
69 80
70 ## LISENCE 81 ## LISENCE
71 ---------- 82 +-------
72 Do-gether is free software, and may be redistributed under the terms specified in the [MIT LICENSE](http://khuhub.khu.ac.kr/2019102153/Do-gether/blob/master/LICENSE.txt) file. 83 Do-gether is free software, and may be redistributed under the terms specified in the [MIT LICENSE](http://khuhub.khu.ac.kr/2019102153/Do-gether/blob/master/LICENSE.txt) file.
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -57,7 +57,6 @@ export default function BodyLayout() { ...@@ -57,7 +57,6 @@ export default function BodyLayout() {
57 callApi() 57 callApi()
58 .then((res) => { 58 .then((res) => {
59 setData(res); 59 setData(res);
60 - console.log(res);
61 setIsLoading(0); 60 setIsLoading(0);
62 }) 61 })
63 .catch((err) => console.log(err)); 62 .catch((err) => console.log(err));
...@@ -76,7 +75,7 @@ export default function BodyLayout() { ...@@ -76,7 +75,7 @@ export default function BodyLayout() {
76 const isMine = card.name === localStorage["userName"]; //remove item 75 const isMine = card.name === localStorage["userName"]; //remove item
77 if (idx === 0 || card.date !== data[idx - 1].date) { 76 if (idx === 0 || card.date !== data[idx - 1].date) {
78 showDate = ( 77 showDate = (
79 - <Typography variant="h4" className={classes.date}> 78 + <Typography key={idx} variant="h4" className={classes.date}>
80 {card.date} 79 {card.date}
81 </Typography> 80 </Typography>
82 ); 81 );
...@@ -90,9 +89,9 @@ export default function BodyLayout() { ...@@ -90,9 +89,9 @@ export default function BodyLayout() {
90 return ( 89 return (
91 <> 90 <>
92 {showDate} 91 {showDate}
93 - <Grid item xs={12} sm={6} md={3}> 92 + <Grid item xs={12} sm={6} md={3} key={idx+1}>
94 <TodoCard 93 <TodoCard
95 - key={card.id} 94 + key={idx}
96 data={card} 95 data={card}
97 isVisible={isVisible} 96 isVisible={isVisible}
98 isMine={isMine} 97 isMine={isMine}
...@@ -105,7 +104,7 @@ export default function BodyLayout() { ...@@ -105,7 +104,7 @@ export default function BodyLayout() {
105 } 104 }
106 })} 105 })}
107 </Grid> 106 </Grid>
108 - <AddButton></AddButton> 107 + <AddButton key="addBtn"></AddButton>
109 </Container> 108 </Container>
110 </div> 109 </div>
111 ); 110 );
......
...@@ -24,6 +24,19 @@ const useStyles = makeStyles((theme) => ({ ...@@ -24,6 +24,19 @@ const useStyles = makeStyles((theme) => ({
24 export default function ButtonAppBar() { 24 export default function ButtonAppBar() {
25 const classes = useStyles(); 25 const classes = useStyles();
26 26
27 + const handleLogout = ()=>{
28 + fetch("/auth/logout",{
29 + method: "GET",
30 + headers : {
31 + 'Content-Type': 'application/json',
32 + 'Accept': 'application/json'
33 + }
34 + });
35 + localStorage.removeItem("userName");
36 + alert("Sucessfully logout!");
37 + window.location.href = "/";
38 + }
39 +
27 return ( 40 return (
28 <div className={classes.root}> 41 <div className={classes.root}>
29 <AppBar className={classes.bar} position="fixed"> 42 <AppBar className={classes.bar} position="fixed">
...@@ -31,7 +44,7 @@ export default function ButtonAppBar() { ...@@ -31,7 +44,7 @@ export default function ButtonAppBar() {
31 <Typography variant="h6" className={classes.title}> 44 <Typography variant="h6" className={classes.title}>
32 Do-gether 45 Do-gether
33 </Typography> 46 </Typography>
34 - <Button color="inherit" className={classes.logout}>Logout</Button> 47 + <Button color="inherit" className={classes.logout} onClick={handleLogout}>Logout</Button>
35 </Toolbar> 48 </Toolbar>
36 </AppBar> 49 </AppBar>
37 </div> 50 </div>
......
...@@ -33,7 +33,6 @@ const useStyles = makeStyles({ ...@@ -33,7 +33,6 @@ const useStyles = makeStyles({
33 33
34 export default function TodoCard({ data, isMine }) { 34 export default function TodoCard({ data, isMine }) {
35 const classes = useStyles(); 35 const classes = useStyles();
36 - const [open, setOpen] = useState(false);
37 const [render, setRender] = useState(0); 36 const [render, setRender] = useState(0);
38 const todo = data.todo.split(",").map((text) => { 37 const todo = data.todo.split(",").map((text) => {
39 return text; 38 return text;
...@@ -49,8 +48,7 @@ export default function TodoCard({ data, isMine }) { ...@@ -49,8 +48,7 @@ export default function TodoCard({ data, isMine }) {
49 let tempArr = checkState; 48 let tempArr = checkState;
50 tempArr[idx] = tempArr[idx] ? 0 : 1; 49 tempArr[idx] = tempArr[idx] ? 0 : 1;
51 setCheckState(tempArr); 50 setCheckState(tempArr);
52 - data.ck=tempArr.join(","); 51 + data.ck = tempArr.join(",");
53 - console.log(data);
54 setRender([]); 52 setRender([]);
55 modifyApi({ 53 modifyApi({
56 isPublic: data.isPublic, 54 isPublic: data.isPublic,
...@@ -96,9 +94,10 @@ export default function TodoCard({ data, isMine }) { ...@@ -96,9 +94,10 @@ export default function TodoCard({ data, isMine }) {
96 {todo.map((item, idx) => { 94 {todo.map((item, idx) => {
97 return ( 95 return (
98 <FormControlLabel 96 <FormControlLabel
97 + key={idx}
99 className={classes.checkBox} 98 className={classes.checkBox}
100 control={<Checkbox onClick={(e) => handleCheck(idx)} />} 99 control={<Checkbox onClick={(e) => handleCheck(idx)} />}
101 - checked={checkState[idx]} 100 + checked={Boolean(checkState[idx])}
102 label={item} 101 label={item}
103 /> 102 />
104 ); 103 );
......
...@@ -62,7 +62,7 @@ export default function LandingPage(props) { ...@@ -62,7 +62,7 @@ export default function LandingPage(props) {
62 const [userPW, setUserPW] = useState(); 62 const [userPW, setUserPW] = useState();
63 63
64 const loginApi = (data) => { 64 const loginApi = (data) => {
65 - return fetch("/api/login", { 65 + return fetch("/auth/login", {
66 method: "POST", 66 method: "POST",
67 headers: { 67 headers: {
68 "Content-Type": "application/json", 68 "Content-Type": "application/json",
...@@ -88,8 +88,6 @@ export default function LandingPage(props) { ...@@ -88,8 +88,6 @@ export default function LandingPage(props) {
88 userID: userID, 88 userID: userID,
89 userPW: userPW, 89 userPW: userPW,
90 }); 90 });
91 - alert("Successfully login!");
92 - props.history.push("/login");
93 } 91 }
94 }; 92 };
95 93
......
1 -import React from "react"; 1 +import React, { useEffect } from "react";
2 import NavBar from "../components/NavBar.js"; 2 import NavBar from "../components/NavBar.js";
3 import BodyLayout from "../components/BodyLayout.js"; 3 import BodyLayout from "../components/BodyLayout.js";
4 4
5 function App() { 5 function App() {
6 +
7 + const checkLogin = async () => {
8 + const response = await fetch("/auth",{
9 + method: "GET",
10 + headers : {
11 + 'Content-Type': 'application/json',
12 + 'Accept': 'application/json'
13 + }
14 + });
15 + const body = await response.json();
16 + return body;
17 + };
18 +
19 + useEffect(() => {
20 + checkLogin().then((res) => {
21 + if(res.message!=="Authenticated user"){
22 + alert("Please login!");
23 + window.location.href="/login";
24 + }
25 + });
26 + });
27 +
6 return ( 28 return (
7 <> 29 <>
8 <NavBar /> 30 <NavBar />
9 - <BodyLayout /> 31 + <BodyLayout key="body"/>
10 </> 32 </>
11 ); 33 );
12 } 34 }
......
...@@ -17,7 +17,5 @@ ...@@ -17,7 +17,5 @@
17 "devDependencies": { 17 "devDependencies": {
18 "concurrently": "^4.0.1" 18 "concurrently": "^4.0.1"
19 }, 19 },
20 - "proxy": "http://localhost:3000/",
21 -
22 "license": "UNLICENSED" 20 "license": "UNLICENSED"
23 } 21 }
......
...@@ -29,11 +29,15 @@ app.use( ...@@ -29,11 +29,15 @@ app.use(
29 secret: "asdjha!@#@#$dd", 29 secret: "asdjha!@#@#$dd",
30 resave: false, 30 resave: false,
31 saveUninitialized: true, 31 saveUninitialized: true,
32 + cookie: {
33 + maxAge: 1000 * 60 * 60 // 쿠키 유효기간 24시간
34 + }
32 }) 35 })
33 ); 36 );
34 37
35 app.get("/api/cards", (req, res) => { 38 app.get("/api/cards", (req, res) => {
36 connection.query("SELECT * FROM CARDINFO", (err, rows, fields) => { 39 connection.query("SELECT * FROM CARDINFO", (err, rows, fields) => {
40 + // console.log(rows);
37 res.send(rows); 41 res.send(rows);
38 }); 42 });
39 }); 43 });
...@@ -127,7 +131,7 @@ app.post("/api/signup", async (req, res) => { ...@@ -127,7 +131,7 @@ app.post("/api/signup", async (req, res) => {
127 }); 131 });
128 }); 132 });
129 133
130 -app.post("/api/login", (req, res) => { 134 +app.post("/auth/login", (req, res) => {
131 const data = req.body; 135 const data = req.body;
132 const enteredID = data.userID; 136 const enteredID = data.userID;
133 const enteredPW = data.userPW; 137 const enteredPW = data.userPW;
...@@ -136,19 +140,16 @@ app.post("/api/login", (req, res) => { ...@@ -136,19 +140,16 @@ app.post("/api/login", (req, res) => {
136 [enteredID], 140 [enteredID],
137 function (error, results, fields) { 141 function (error, results, fields) {
138 if (error) { 142 if (error) {
139 - // console.log("error ocurred", error);
140 res.send({ 143 res.send({
141 code: 400, 144 code: 400,
142 message: "error ocurred", 145 message: "error ocurred",
143 }); 146 });
144 } else { 147 } else {
145 - // console.log('The solution is: ', results);
146 if (results.length > 0) { 148 if (results.length > 0) {
147 bcrypt.compare(enteredPW, results[0].userPW, function (err, check) { 149 bcrypt.compare(enteredPW, results[0].userPW, function (err, check) {
148 - console.log(check);
149 if (check) { 150 if (check) {
150 req.session.userName = results[0].userName; 151 req.session.userName = results[0].userName;
151 - console.log(req.session.userName); 152 + console.log(req.session.userName + "is login");
152 res.send({ 153 res.send({
153 code: 200, 154 code: 200,
154 message: "login sucessfull", 155 message: "login sucessfull",
...@@ -171,4 +172,29 @@ app.post("/api/login", (req, res) => { ...@@ -171,4 +172,29 @@ app.post("/api/login", (req, res) => {
171 } 172 }
172 ); 173 );
173 }); 174 });
175 +
176 +app.get("/auth/logout", async (req,res,next) => {
177 + console.log(req.session.userName+ "is logout");
178 + req.session.destroy();
179 + res.clearCookie('sid');
180 + res.redirect("/");
181 +})
182 +
183 +app.get("/auth", (req,res) =>{
184 + try{
185 + if(req.session.userName){
186 + res.send({
187 + message: "Authenticated user"
188 + })
189 + }else{
190 + console.log("Unauthorized access")
191 + res.send({
192 + message: "Unauthenticated user"
193 + })
194 + }
195 + }catch(e){
196 + console.log(e);
197 + }
198 +})
199 +
174 app.listen(port, () => console.log(`Listening on port ${port}`)); 200 app.listen(port, () => console.log(`Listening on port ${port}`));
......