고병후

Make logout

1 +const express = require("express");
2 +
3 +var auth = function (req, res, next) {
4 + // Session Check
5 + // 어드민 여부 체크 필요
6 + console.log(req.session.name);
7 + if (req.session.name != null && req.session.name != undefined)
8 + next();
9 + else{
10 + console.log("미가입자 접근")
11 + res.sendStatus(401);
12 + }
13 +
14 +
15 +};
16 +
17 +module.exports = auth;
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require("express");
2 +const bodyParser = require("body-parser");
3 +const router = express.Router();
4 +
5 +
6 +
7 +router.get('/',(req,res)=>{
8 + if (req.session.name != null && req.session.name != undefined){
9 + console.log("req.session.name");
10 + res.sendStatus(200);
11 + }
12 + else{
13 + console.log("미가입자 접근");
14 + res.sendStatus(401);
15 + }
16 +});
17 +
18 +
19 +
20 +
21 +module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require("express");
2 +const bodyParser = require("body-parser");
3 +const router = express.Router();
4 +
5 +const {User}=require('../models');
6 +
7 +router.get('/',(req,res)=>{
8 +
9 +});
10 +
11 +//로그아웃
12 +router.post('/',(req,res)=>{
13 + if(result.dataValues.pw == req.body.Password){
14 + req.session.id = null;
15 + req.session.name = null;
16 + req.session.personality = null;
17 + req.session.status = null;
18 + req.session.isAuthorized = null;
19 + console.log("Logout");
20 + res.sendStatus(200);
21 + }
22 + })
23 +
24 + module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
1 const express = require("express"); 1 const express = require("express");
2 const bodyParser = require("body-parser"); 2 const bodyParser = require("body-parser");
3 const router = express.Router(); 3 const router = express.Router();
4 +const auth = require("../obj/authorize");
4 5
5 const {User}=require('../models'); 6 const {User}=require('../models');
6 7
7 -router.get('/',(req,res)=>{ 8 +router.get('/',auth,(req,res)=>{
8 //메인페이지 9 //메인페이지
9 10
10 //테스트 코드 11 //테스트 코드
......
...@@ -14,6 +14,8 @@ const indexRouter = require('./routes/index.js'); ...@@ -14,6 +14,8 @@ const indexRouter = require('./routes/index.js');
14 const loginRouter = require('./routes/login.js'); 14 const loginRouter = require('./routes/login.js');
15 const registerRouter = require('./routes/register.js'); 15 const registerRouter = require('./routes/register.js');
16 const mainRouter = require('./routes/main.js'); 16 const mainRouter = require('./routes/main.js');
17 +const logoutRouter = require('./routes/logout.js');
18 +const authRouter = require('./routes/auth.js');
17 19
18 const app = express(); 20 const app = express();
19 app.set('port', process.env.PORT || 3001); 21 app.set('port', process.env.PORT || 3001);
...@@ -49,6 +51,9 @@ app.use(session({ ...@@ -49,6 +51,9 @@ app.use(session({
49 app.use('/api/register',registerRouter); // 회원가입 페이지 51 app.use('/api/register',registerRouter); // 회원가입 페이지
50 app.use('/api/login',loginRouter); //로그인 페이지 52 app.use('/api/login',loginRouter); //로그인 페이지
51 app.use('/api/main',mainRouter);//메인페이지 53 app.use('/api/main',mainRouter);//메인페이지
54 +app.use('/api/auth',authRouter);//가입여부 확인
55 +app.use('/api/logout',logoutRouter);//로그아웃
56 +
52 57
53 58
54 //에러처리 미들웨어 59 //에러처리 미들웨어
......