Song

git push

...@@ -23,8 +23,8 @@ var connect = mongoose.connect('mongodb://127.0.0.1:27017/cookBook', { ...@@ -23,8 +23,8 @@ var connect = mongoose.connect('mongodb://127.0.0.1:27017/cookBook', {
23 useMongoClient: true, 23 useMongoClient: true,
24 }); 24 });
25 25
26 -//admin module get 26 +//categori module get
27 -var admin = require('./routes/admin'); 27 +var categori = require('./routes/categori');
28 var accounts = require('./routes/accounts'); 28 var accounts = require('./routes/accounts');
29 var auth = require('./routes/auth'); 29 var auth = require('./routes/auth');
30 var connectMongo = require('connect-mongo'); 30 var connectMongo = require('connect-mongo');
...@@ -69,7 +69,7 @@ app.use(function (req, res, next) { ...@@ -69,7 +69,7 @@ app.use(function (req, res, next) {
69 69
70 //routes add 70 //routes add
71 app.use('/', Search); 71 app.use('/', Search);
72 -app.use('/admin', admin); 72 +app.use('/categori', categori);
73 app.use('/accounts', accounts); 73 app.use('/accounts', accounts);
74 app.use('/auth', auth); 74 app.use('/auth', auth);
75 75
......
1 -require('./removeByValue')();
2 -var userList = []; //사용자 리스트를 저장할곳
3 -module.exports = function(io) {
4 - io.on('connection', function(socket){
5 -
6 - var session = socket.request.session.passport;
7 - var user = (typeof session !== 'undefined') ? ( session.user ) : "";
8 -
9 - // userList 필드에 사용자 명이 존재 하지 않으면 삽입
10 - if(userList.indexOf(user.displayname) === -1){
11 - userList.push(user.displayname);
12 - }
13 - io.emit('join', userList);
14 -
15 - //사용자 명과 메시지를 같이 반환한다.
16 - socket.on('client message', function(data){
17 - io.emit('server message', { message : data.message , displayname : user.displayname });
18 - });
19 -
20 - socket.on('disconnect', function(){
21 - userList.removeByValue(user.displayname);
22 - io.emit('leave', userList);
23 - });
24 -
25 - });
26 -};
...\ No newline at end of file ...\ No newline at end of file
1 +var mongoose = require('mongoose');
2 +var Schema = mongoose.Schema;
3 +
4 +var CategoriSchema = new Schema({
5 + title: {
6 + type: String,
7 + required: [true, '카테고리명을 입력해주세요'],
8 + },
9 + videoNum: String,
10 + description: String, //설명
11 + created_at: {
12 + type: Date,
13 + default: Date.now(),
14 + },
15 + username: String,
16 +});
17 +
18 +CategoriSchema.virtual('getDate').get(function () {
19 + var date = new Date(this.created_at);
20 + return {
21 + year: date.getFullYear(),
22 + month: date.getMonth() + 1,
23 + day: date.getDate(),
24 + };
25 +});
26 +
27 +module.exports = mongoose.model('categories', CategoriSchema);
...\ No newline at end of file ...\ No newline at end of file
1 +var mongoose = require('mongoose');
2 +var Schema = mongoose.Schema;
3 +var VideoSchema = new Schema({
4 + username: {
5 + type: String,
6 + required: [true, '아이디는 필수입니다.'],
7 + },
8 + password: {
9 + type: String,
10 + required: [true, '패스워드는 필수입니다.'],
11 + },
12 + displayname: String,
13 + created_at: {
14 + type: Date,
15 + default: Date.now(),
16 + },
17 +});
18 +
19 +module.exports = mongoose.model('videos', VideoSchema);
1 -var mongoose = require('mongoose');
2 -var Schema = mongoose.Schema;
3 -var VideoSchema = new Schema({
4 - name: String,
5 - title: String,
6 - videoId: String,
7 - description: String, //설명
8 - url: String,
9 -});
10 -
11 -module.exports = mongoose.model('videos', VideoSchema);
1 var express = require('express'); 1 var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 -var ProductsModel = require('../models/ProductsModel'); 3 +var CategoriModel = require('../models/CategoriModel');
4 -var CommentsModel = require('../models/VideoModels');
5 var csrf = require('csurf'); 4 var csrf = require('csurf');
6 var csrfProtection = csrf({ cookie: true }); 5 var csrfProtection = csrf({ cookie: true });
7 var loginRequired = require('../libs/loginRequired'); 6 var loginRequired = require('../libs/loginRequired');
...@@ -29,16 +28,16 @@ var storage = multer.diskStorage({ ...@@ -29,16 +28,16 @@ var storage = multer.diskStorage({
29 var upload = multer({ storage: storage }); 28 var upload = multer({ storage: storage });
30 29
31 router.get('/', function (req, res) { 30 router.get('/', function (req, res) {
32 - res.send('admin main page'); 31 + res.send('categori main page');
33 }); 32 });
34 33
35 router.get('/products', function (req, res) { 34 router.get('/products', function (req, res) {
36 - ProductsModel.find(function (err, products) { 35 + CategoriModel.find(function (err, products) {
37 res.render( 36 res.render(
38 'admin/products', 37 'admin/products',
39 { products: products } 38 { products: products }
40 //ProductModel의 products를 받아서 39 //ProductModel의 products를 받아서
41 - //admin/products로 response를 보낸다. 40 + //categori/products로 response를 보낸다.
42 ); 41 );
43 }); 42 });
44 }); 43 });
...@@ -49,7 +48,7 @@ router.get( ...@@ -49,7 +48,7 @@ router.get(
49 csrfProtection, 48 csrfProtection,
50 function (req, res) { 49 function (req, res) {
51 //edit에서도 같은 form을 사용하므로 빈 변수( product )를 넣어서 에러를 피해준다 50 //edit에서도 같은 form을 사용하므로 빈 변수( product )를 넣어서 에러를 피해준다
52 - res.render('admin/form', { product: '', csrfToken: req.csrfToken() }); 51 + res.render('categori/form', { product: '', csrfToken: req.csrfToken() });
53 } 52 }
54 ); 53 );
55 54
...@@ -59,7 +58,7 @@ router.post( ...@@ -59,7 +58,7 @@ router.post(
59 loginRequired, 58 loginRequired,
60 csrfProtection, 59 csrfProtection,
61 function (req, res) { 60 function (req, res) {
62 - var product = new ProductsModel({ 61 + var product = new CategoriModel({
63 name: req.body.name, 62 name: req.body.name,
64 thumbnail: req.file ? req.file.filename : '', 63 thumbnail: req.file ? req.file.filename : '',
65 price: req.body.price, 64 price: req.body.price,
...@@ -72,7 +71,7 @@ router.post( ...@@ -72,7 +71,7 @@ router.post(
72 res.send(validationError); 71 res.send(validationError);
73 } else { 72 } else {
74 product.save(function (err) { 73 product.save(function (err) {
75 - res.redirect('/admin/products'); 74 + res.redirect('/categori/products');
76 }); 75 });
77 } 76 }
78 //이 위는 수정되지 않았음 77 //이 위는 수정되지 않았음
...@@ -81,10 +80,10 @@ router.post( ...@@ -81,10 +80,10 @@ router.post(
81 80
82 router.get('/products/detail/:id', function (req, res) { 81 router.get('/products/detail/:id', function (req, res) {
83 //url 에서 변수 값을 받아올떈 req.params.id 로 받아온다 82 //url 에서 변수 값을 받아올떈 req.params.id 로 받아온다
84 - ProductsModel.findOne({ id: req.params.id }, function (err, product) { 83 + CategoriModel.findOne({ id: req.params.id }, function (err, product) {
85 //제품정보를 받고 그안에서 댓글을 받아온다. 84 //제품정보를 받고 그안에서 댓글을 받아온다.
86 - CommentsModel.find({ product_id: req.params.id }, function (err, comments) { 85 + CategoriModel.find({ product_id: req.params.id }, function (err, comments) {
87 - res.render('admin/productsDetail', { 86 + res.render('categori/productsDetail', {
88 product: product, 87 product: product,
89 comments: comments, 88 comments: comments,
90 }); 89 });
...@@ -98,8 +97,8 @@ router.get( ...@@ -98,8 +97,8 @@ router.get(
98 csrfProtection, 97 csrfProtection,
99 function (req, res) { 98 function (req, res) {
100 //기존에 폼에 value안에 값을 셋팅하기 위해 만든다. 99 //기존에 폼에 value안에 값을 셋팅하기 위해 만든다.
101 - ProductsModel.findOne({ id: req.params.id }, function (err, product) { 100 + CategoriModel.findOne({ id: req.params.id }, function (err, product) {
102 - res.render('admin/form', { 101 + res.render('categori/form', {
103 product: product, 102 product: product,
104 csrfToken: req.csrfToken(), 103 csrfToken: req.csrfToken(),
105 }); 104 });
...@@ -114,7 +113,7 @@ router.post( ...@@ -114,7 +113,7 @@ router.post(
114 csrfProtection, 113 csrfProtection,
115 function (req, res) { 114 function (req, res) {
116 //그전에 지정되 있는 파일명을 받아온다 115 //그전에 지정되 있는 파일명을 받아온다
117 - ProductsModel.findOne({ id: req.params.id }, function (err, product) { 116 + CategoriModel.findOne({ id: req.params.id }, function (err, product) {
118 //아래의 코드만 추가되면 된다. 117 //아래의 코드만 추가되면 된다.
119 if (req.file && product.thumbnail) { 118 if (req.file && product.thumbnail) {
120 //요청중에 파일이 존재 할시 이전이미지 지운다. 119 //요청중에 파일이 존재 할시 이전이미지 지운다.
...@@ -128,11 +127,11 @@ router.post( ...@@ -128,11 +127,11 @@ router.post(
128 price: req.body.price, 127 price: req.body.price,
129 description: req.body.description, 128 description: req.body.description,
130 }; 129 };
131 - ProductsModel.update( 130 + CategoriModel.update(
132 { id: req.params.id }, 131 { id: req.params.id },
133 { $set: query }, 132 { $set: query },
134 function (err) { 133 function (err) {
135 - res.redirect('/admin/products/detail/' + req.params.id); 134 + res.redirect('/categori/products/detail/' + req.params.id);
136 } 135 }
137 ); 136 );
138 }); 137 });
...@@ -140,13 +139,13 @@ router.post( ...@@ -140,13 +139,13 @@ router.post(
140 ); 139 );
141 140
142 router.get('/products/delete/:id', function (req, res) { 141 router.get('/products/delete/:id', function (req, res) {
143 - ProductsModel.remove({ id: req.params.id }, function (err) { 142 + CategoriModel.remove({ id: req.params.id }, function (err) {
144 - res.redirect('/admin/products'); 143 + res.redirect('/categori/products');
145 }); 144 });
146 }); 145 });
147 146
148 router.post('/products/ajax_comment/insert', function (req, res) { 147 router.post('/products/ajax_comment/insert', function (req, res) {
149 - var comment = new CommentsModel({ 148 + var comment = new CategoriModel({
150 content: req.body.content, 149 content: req.body.content,
151 product_id: parseInt(req.body.product_id), 150 product_id: parseInt(req.body.product_id),
152 }); 151 });
...@@ -160,7 +159,7 @@ router.post('/products/ajax_comment/insert', function (req, res) { ...@@ -160,7 +159,7 @@ router.post('/products/ajax_comment/insert', function (req, res) {
160 }); 159 });
161 160
162 router.post('/products/ajax_comment/delete', function (req, res) { 161 router.post('/products/ajax_comment/delete', function (req, res) {
163 - CommentsModel.remove({ id: req.body.comment_id }, function (err) { 162 + CategoriModel.remove({ id: req.body.comment_id }, function (err) {
164 res.json({ message: 'success' }); 163 res.json({ message: 'success' });
165 }); 164 });
166 }); 165 });
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
10 </div> 10 </div>
11 <div class="panel-body"> 11 <div class="panel-body">
12 <form role="form" action="" id="login_form" method="post"> 12 <form role="form" action="" id="login_form" method="post">
13 - <fieldset> 13 + QKQKQfieldset>
14 <div class="form-group"> 14 <div class="form-group">
15 <input class="form-control" placeholder="ID" name="username" type="text" autofocus="" required=""> 15 <input class="form-control" placeholder="ID" name="username" type="text" autofocus="" required="">
16 </div> 16 </div>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
3 <input type="hidden" name="_csrf" value="<%=csrfToken%>" /> 3 <input type="hidden" name="_csrf" value="<%=csrfToken%>" />
4 <table class="table table-bordered"> 4 <table class="table table-bordered">
5 <tr> 5 <tr>
6 - <th>제품명</th> 6 + <th>카테고리명</th>
7 <td><input type="text" name="name" class="form-control" value="<%=product.name%>"/></td> 7 <td><input type="text" name="name" class="form-control" value="<%=product.name%>"/></td>
8 </tr> 8 </tr>
9 <tr> 9 <tr>
......
1 <% include ../includes/header.ejs %> 1 <% include ../includes/header.ejs %>
2 <table class="table table-bordered table-hover"> 2 <table class="table table-bordered table-hover">
3 <tr> 3 <tr>
4 - <th>제목</th> 4 + <th width="100px" style="text-align: center;">카테고리명</th>
5 - <th>작성일</th> 5 + <th style="text-align: center;">영상 개수</th>
6 + <th>내용</th>
6 <th>삭제</th> 7 <th>삭제</th>
7 </tr> 8 </tr>
8 <%products.forEach(function(product){%> 9 <%products.forEach(function(product){%>
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
33 <li class="active"> 33 <li class="active">
34 <a href="/">Home</a> 34 <a href="/">Home</a>
35 </li> 35 </li>
36 - <li><a href="/admin/products">Categori</a></li> 36 + <li><a href="/categori/products">Categori</a></li>
37 <% if(isLogin){%> 37 <% if(isLogin){%>
38 <li><a href="/accounts/logout" onclick="return confirm('로그아웃 하시겠습니까?')">LOGOUT</a></li> 38 <li><a href="/accounts/logout" onclick="return confirm('로그아웃 하시겠습니까?')">LOGOUT</a></li>
39 <%}else{%> 39 <%}else{%>
......