Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gain qna result #28

Open
wants to merge 16 commits into
base: gain
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ const fs = require('fs');
const url = require('url');
const path = require('path');
const db = require('./db.js');
const session = require('express-session');

const mainRouter = require('./routes/main.js');
const loginRouter = require('./routes/login.js');
const loginProcessRouter = require('./routes/login_process.js');
const logoutProcessRouter = require('./routes/logout_process.js');
const signupRouter = require('./routes/signup.js');
const signupProcessRouter = require('./routes/signup_process.js');

Expand Down Expand Up @@ -43,7 +47,19 @@ app.use(express.static('public'));


app.use('/', mainRouter);
app.use(express.static('public'));
app.use(session({
key:'my key',
secret: 'secret',
resave: false,
saveUninitialize: true,
cookie:{
maxAge: 60 * 60 * 24 * 1
}
}));
app.get('/login', loginRouter);
app.post('/login_process',loginProcessRouter);
app.get('/logout_process',logoutProcessRouter);
app.get('/signup', signupRouter);
app.post('/signup_process', signupProcessRouter);

Expand Down
16 changes: 16 additions & 0 deletions lib/author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
isOwner:function(request, response) {
if (request.session.is_logined) {
return true;
} else {
return false;
}
},
statusUI:function(request, response) {
var authStatusUI = '<a href="/login">로그인</a>'
if (this.isOwner(request, response)) {
authStatusUI = `| <a href="/logout_process">로그아웃</a>`;
}
return authStatusUI;
}
}
8 changes: 4 additions & 4 deletions lib/template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
HTML: function (title, head, body) {
HTML: function (title, head, body, authStatusUI = '<a href="/login">로그인</a>') {
return `
<html>
<head>
Expand Down Expand Up @@ -66,7 +66,7 @@ module.exports = {
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item dropdown">
<a class="nav-link active" aria-current="page" href="#">제품소개</a>
<a class="nav-link active" aria-current="page" href="/store/pad">제품소개</a>
<div class="dropdown-content">
<a href="/store/pad">일회용 월경대</a>
<a href="/store/cpad">면 월경대</a>
Expand All @@ -76,14 +76,14 @@ module.exports = {
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link active" aria-current="page" href="#">자유게시판</a>
<a class="nav-link active" aria-current="page" href="/community/recommendation">자유게시판</a>
<div class="dropdown-content">
<a href="/community/recommendation">제품추천</a>
<a href="/community/requirement">For me에게 바란다</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="/login">로그인</a>
${authStatusUI}
</li>
<li class="nav-item">
<a class="nav-link" href="/signup">회원가입</a>
Expand Down
93 changes: 90 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/images/create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/create2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/image-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/image-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/mypage2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/mypage3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/recommendation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/requirement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 44 additions & 14 deletions routes/community/create_rec.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
var express = require('express');
var router = express.Router();
var template = require('../../lib/template.js');
var author = require('../../lib/author.js');
const db = require('../../db.js');

router.get('/community/recommendation/create', function (request, response) {
var title = '추천글쓰기';
var head = `
<style>
.create_main{
margin-top:200px;
}
body {
text-align: center;
background-color : #EEEEEE;
}
.formbox {
display : inline-block;
background-color: white;
width: 800px;
text-align: center;
border: 1px solid black;
margin-top: 100px auto;
border-radius: 30px;
padding-bottom: 30px;
}
textarea {
width: 100%;
height: 60%;
border: none;
resize: none;
}

.input {
width: 100%;
border: none;
resize: none;
}
</style>
`;
var body = `
<main class="flex-shrink-0">
<div class="create_main">
<form action="/community/recommendation/create_process" method="post">
<input class="input" type='text' name="title" placeholder='제목'/>
<br>
<hr>
<textarea class="input" name="content" placeholder='내용'></textarea>
<div class="submit_btn">
<input id="submit_button" size="sm" type="submit" value="저장">
</div>
</form>
<div class="container">
<br>
<img src='/images/create.png' width = "400px">
<br><br>
<div class="formbox">
<br>
<form action="/community/recommendation/create_process" method="post">
<input class="input" type='text' name="title" placeholder='제목'>
<br>
<hr>
<textarea class="input" name="content" placeholder='내용'></textarea>
<div class="submit_btn">
<input id="submit_button" size="sm" type="submit" value="저장">
</div>
</form>
</div>
</div>
</main>
`;
var html = template.HTML(title, head, body);
var html = template.HTML(title, head, body, author.statusUI(request, response));
response.send(html);
});

Expand Down
2 changes: 1 addition & 1 deletion routes/community/create_rec_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ router.post('/community/recommendation/create_process', function (request, respo
var title = post.title;
var content = post.content;
var date = new Date();
var writer = 'donut@forme.com'; //로그인한 사용자로 수정 필요!!!!
var writer = 'naeyoung123@naver.com'; //로그인한 사용자로 수정 필요!!!!
db.query(`INSERT INTO recommendation (title, content, date, writer) VALUES(?, ?, ?, ?)`, [title, content, date, writer], function(err, res){
if(err) throw err;
response.writeHead(302, {Location: `/community/recommendation`});
Expand Down
Loading