min1925k@gmail.com

session with Logout

......@@ -7,6 +7,7 @@ var bodyParser = require('body-parser')
var expressErrorHandler = require('express-error-handler');
var indexRouter = require('./routes/index')
var loginRouter = require('./routes/login')
var logoutRouter = require('./routes/logout')
var signupRouter = require('./routes/signup')
var lpgRouter = require('./routes/lpg')
var weatherRouter = require('./routes/weather')
......@@ -21,7 +22,7 @@ var app = express();
var router = express.Router();
var cookieParser = require('cookie-parser')
var ExpressSession = require('express-session')
var session = require('express-session')
var database = require('./database/database');
var config = require('./config');
......@@ -46,11 +47,19 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js')); // redirect bootstrap JS
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css')); // redirect CSS bootstrap
//Session 처리
app.use(cookieParser());
app.use(session({
secret:'key',
resave: true,
saveUninitialized:true
}));
//
app.use('/csv',csvRouter)
app.use('/menu',menuRouter)
app.use('/login',loginRouter); // login page route
app.use('/logout',logoutRouter); // login page route
app.use('/weather',weatherRouter)
app.use('/lpg',lpgRouter)
app.use('/signup',signupRouter); // sign up page route
......@@ -60,13 +69,6 @@ app.use('/showpost',showpostRouter);
app.use('/', indexRouter); // main page route
//Session 처리
app.use(cookieParser());
app.use(ExpressSession({
secret:'key',
resave: true,
saveUninitialized:true
}));
//모든 router 처리가 끝난 후 404 오류 페이지 처리
var errorHandler = expressErrorHandler({
......
......@@ -5,7 +5,9 @@ var router = express.Router();
router.get('/',function(req,res){
res.render('index.html')
res.render('index.html', {
session : req.session
})
})
......
......@@ -36,13 +36,16 @@ router.post('/process', function(req, res) {
// 조회된 레코드가 있으면 성공 응답 전송
if (docs) {
console.dir(docs);
req.session.sessId = paramId;
req.session.save();
// 조회 결과에서 사용자 이름 확인
res.render('/')
res.render('index.html',{
session : req.session
});
} else { // 조회된 레코드가 없는 경우 실패 응답 전송
res.render('/')
res.render('login.html');
}
});
......
var Conn = require('../database/database')
var express = require('express')
var router = express.Router();
//라우팅 함수 등록
router.get('/',function(req,res){
req.session.destroy(function() {
req.session;
});
res.render('index.html')
});
module.exports = router
\ No newline at end of file
var express = require('express')
var router = express.Router()
var Entities = require('html-entities').AllHtmlEntities;
......@@ -39,6 +38,7 @@ router.get('/',function(req,res){
// 뷰 템플레이트를 이용하여 렌더링한 후 전송
var context = {
session: req.session,
title: '글 목록',
posts: results,
page: parseInt(paramPage),
......
......@@ -4,7 +4,9 @@ var router = express.Router()
var Entities = require('html-entities').AllHtmlEntities;
router.get('/',function(req,res){
res.render('postadd.ejs');
res.render('postadd.ejs',{
session : req.session
});
})
module.exports = router;
......
File mode changed
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Modern Business - Start Bootstrap Template</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-2.1.4.js"></script>
</head>
<body class="d-flex flex-column h-100">
<main class="flex-shrink-0">
<!-- Navigation-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container px-5">
<a class="navbar-brand" href="/">휴게소 정보</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"><span
class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
<li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
<li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
<li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
<li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
<% if(session.sessId){ %>
<li class="nav-item"><a class="nav-link" href="/logout">Log-Out</a></li>
<% } else { %>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdownLogin" href="#" role="button"
data-bs-toggle="dropdown" aria-expanded="false">Login</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownLogin">
<li><a class="dropdown-item" href="/login">Login</a></li>
<li><a class="dropdown-item" href="/signup">Sign-up</a></li>
</ul>
</li>
<% } %>
</ul>
</div>
</div>
</nav>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Modern Business - Start Bootstrap Template</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-2.1.4.js"></script>
</head>
<body class="d-flex flex-column h-100">
<main class="flex-shrink-0">
<!-- Navigation-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container px-5">
<a class="navbar-brand" href="/">휴게소 정보</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"><span
class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
<li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
<li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
<li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
<li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button"
data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
<li><a class="dropdown-item" href="blog-home.html">Blog Home</a></li>
<li><a class="dropdown-item" href="blog-post.html">Blog Post</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdownLogin" href="#" role="button"
data-bs-toggle="dropdown" aria-expanded="false">Login</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownLogin">
<li><a class="dropdown-item" href="/login">Login</a></li>
<li><a class="dropdown-item" href="/signup">Sign-up</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<%- include('./header.ejs') %>
<!-- Page Content-->
<div class="container">
<br>
......