min1925k@gmail.com

Board List

...@@ -12,6 +12,9 @@ var lpgRouter = require('./routes/lpg') ...@@ -12,6 +12,9 @@ var lpgRouter = require('./routes/lpg')
12 var weatherRouter = require('./routes/weather') 12 var weatherRouter = require('./routes/weather')
13 var menuRouter = require('./routes/menu') 13 var menuRouter = require('./routes/menu')
14 var csvRouter = require('./routes/csv') 14 var csvRouter = require('./routes/csv')
15 +var postRouter = require('./routes/post')
16 +var postaddRouter = require('./routes/postadd')
17 +
15 var app = express(); 18 var app = express();
16 var router = express.Router(); 19 var router = express.Router();
17 20
...@@ -49,6 +52,8 @@ app.use('/login',loginRouter); // login page route ...@@ -49,6 +52,8 @@ app.use('/login',loginRouter); // login page route
49 app.use('/weather',weatherRouter) 52 app.use('/weather',weatherRouter)
50 app.use('/lpg',lpgRouter) 53 app.use('/lpg',lpgRouter)
51 app.use('/signup',signupRouter); // sign up page route 54 app.use('/signup',signupRouter); // sign up page route
55 +app.use('/post',postRouter);
56 +app.use('/postadd',postaddRouter);
52 app.use('/', indexRouter); // main page route 57 app.use('/', indexRouter); // main page route
53 58
54 59
......
...@@ -2,6 +2,8 @@ module.exports = { ...@@ -2,6 +2,8 @@ module.exports = {
2 server_port: 3000, 2 server_port: 3000,
3 db_url: 'mongodb://oss:12341234@cluster0.us5lm.mongodb.net/?retryWrites=true&w=majority', 3 db_url: 'mongodb://oss:12341234@cluster0.us5lm.mongodb.net/?retryWrites=true&w=majority',
4 db_schemas: [ 4 db_schemas: [
5 - {file:'./user_schema', collection:'users3', schemaName:'UserSchema', modelName:'UserModel'} 5 + {file:'./user_schema', collection:'users', schemaName:'UserSchema', modelName:'UserModel'},
6 + {file:'./post_schema.js', collection:'post', schemaName:'PostSchema', modelName:'PostModel'}
6 ] 7 ]
8 +
7 } 9 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -4,16 +4,12 @@ var db_url = 'mongodb+srv://oss:12341234@cluster0.us5lm.mongodb.net/?retryWrites ...@@ -4,16 +4,12 @@ var db_url = 'mongodb+srv://oss:12341234@cluster0.us5lm.mongodb.net/?retryWrites
4 var database = {}; 4 var database = {};
5 5
6 // 초기화를 위해 호출하는 함수 6 // 초기화를 위해 호출하는 함수
7 -database.init = function(app, config) { 7 +database.init = function(app, config) {
8 - console.log('init() 호출됨.');
9 -
10 connect(app, config); 8 connect(app, config);
11 } 9 }
12 10
13 //데이터베이스에 연결하고 응답 객체의 속성으로 db 객체 추가 11 //데이터베이스에 연결하고 응답 객체의 속성으로 db 객체 추가
14 -function connect(app, config) { 12 +function connect(app, config) {
15 - console.log('connect() 호출됨.');
16 -
17 // 데이터베이스 연결 : config의 설정 사용 13 // 데이터베이스 연결 : config의 설정 사용
18 mongoose.Promise = global.Promise; // mongoose의 Promise 객체는 global의 Promise 객체 사용하도록 함 14 mongoose.Promise = global.Promise; // mongoose의 Promise 객체는 global의 Promise 객체 사용하도록 함
19 mongoose.connect(db_url); 15 mongoose.connect(db_url);
...@@ -35,27 +31,22 @@ function connect(app, config) { ...@@ -35,27 +31,22 @@ function connect(app, config) {
35 // config에 정의된 스키마 및 모델 객체 생성 31 // config에 정의된 스키마 및 모델 객체 생성
36 function createSchema(app, config) { 32 function createSchema(app, config) {
37 var schemaLen = config.db_schemas.length; 33 var schemaLen = config.db_schemas.length;
38 - console.log('설정에 정의된 스키마의 수 : %d', schemaLen);
39 34
40 for (var i = 0; i < schemaLen; i++) { 35 for (var i = 0; i < schemaLen; i++) {
41 var curItem = config.db_schemas[i]; 36 var curItem = config.db_schemas[i];
42 37
43 // 모듈 파일에서 모듈 불러온 후 createSchema() 함수 호출하기 38 // 모듈 파일에서 모듈 불러온 후 createSchema() 함수 호출하기
44 var curSchema = require(curItem.file).createSchema(mongoose); 39 var curSchema = require(curItem.file).createSchema(mongoose);
45 - console.log('%s 모듈을 불러들인 후 스키마 정의함.', curItem.file);
46 40
47 // User 모델 정의 41 // User 모델 정의
48 var curModel = mongoose.model(curItem.collection, curSchema); 42 var curModel = mongoose.model(curItem.collection, curSchema);
49 - console.log('%s 컬렉션을 위해 모델 정의함.', curItem.collection);
50 43
51 // database 객체에 속성으로 추가 44 // database 객체에 속성으로 추가
52 database[curItem.schemaName] = curSchema; 45 database[curItem.schemaName] = curSchema;
53 database[curItem.modelName] = curModel; 46 database[curItem.modelName] = curModel;
54 - console.log('스키마 이름 [%s], 모델 이름 [%s] 이 database 객체의 속성으로 추가됨.', curItem.schemaName, curItem.modelName);
55 } 47 }
56 48
57 app.set('database', database); 49 app.set('database', database);
58 - console.log('database 객체가 app 객체의 속성으로 추가됨.');
59 } 50 }
60 51
61 52
......
1 +var SchemaObj = {};
2 +
3 + SchemaObj.createSchema = function(mongoose) {
4 +
5 + // 글 스키마 정의
6 + var PostSchema = mongoose.Schema({
7 + title: {type: String, trim: true, 'default':''}, // 글 제목
8 + contents: {type: String, trim:true, 'default':''}, // 글 내용
9 + writer: {type: mongoose.Schema.ObjectId, ref: 'users'}, // 글쓴 사람
10 + comments: [{ // 댓글
11 + contents: {type: String, trim:true, 'default': ''}, // 댓글 내용
12 + writer: {type: mongoose.Schema.ObjectId, ref: 'users'},
13 + created_at: {type: Date, 'default': Date.now}
14 + }],
15 + tags: {type: [], 'default': ''},
16 + created_at: {type: Date, index: {unique: false}, 'default': Date.now},
17 + updated_at: {type: Date, index: {unique: false}, 'default': Date.now}
18 + });
19 +
20 + // 필수 속성에 대한 'required' validation
21 + PostSchema.path('title').required(true, '글 제목을 입력하셔야 합니다.');
22 + PostSchema.path('contents').required(true, '글 내용을 입력하셔야 합니다.');
23 +
24 + // 스키마에 인스턴스 메소드 추가
25 + PostSchema.methods = {
26 + savePost: function(callback) { // 글 저장
27 + var self = this;
28 +
29 + this.validate(function(err) {
30 + if (err) return callback(err);
31 +
32 + self.save(callback);
33 + });
34 + },
35 + addComment: function(user, comment, callback) { // 댓글 추가
36 + this.comment.push({
37 + contents: comment.contents,
38 + writer: user._id
39 + });
40 +
41 + this.save(callback);
42 + },
43 + removeComment: function(id, callback) { // 댓글 삭제
44 + var index = utils.indexOf(this.comments, {id: id});
45 + if (~index) {
46 + this.comments.splice(index, 1);
47 + } else {
48 + return callback('ID [' + id + '] 를 가진 댓글 객체를 찾을 수 없습니다.');
49 + }
50 +
51 + this.save(callback);
52 + }
53 + }
54 +
55 + PostSchema.statics = {
56 + // ID로 글 찾기
57 + load: function(id, callback) {
58 + this.findOne({_id: id})
59 + .populate('writer', 'name provider email')
60 + .populate('comments.writer')
61 + .exec(callback);
62 + },
63 + list: function(options, callback) {
64 + var criteria = options.criteria || {};
65 +
66 + this.find(criteria)
67 + .populate('writer', 'name provider email')
68 + .sort({'created_at': -1})
69 + .limit(Number(options.perPage))
70 + .skip(options.perPage * options.page)
71 + .exec(callback);
72 + }
73 + }
74 +
75 + return PostSchema;
76 + };
77 +
78 + // module.exports에 PostSchema 객체 직접 할당
79 + module.exports = SchemaObj;
80 +
81 +
82 + /**
83 + * 배열 객체 안의 배열 요소가 가지는 인덱스 값 리턴
84 + */
85 +function indexOf(arr, obj) {
86 + var index = -1;
87 + var keys = Object.keys(obj);
88 +
89 + var result = arr.filter(function (doc, idx) {
90 + var matched = 0;
91 +
92 + for (var i = keys.length - 1; i >= 0; i--) {
93 + if (doc[keys[i]] === obj[keys[i]]) {
94 + matched++;
95 +
96 + if (matched === keys.length) {
97 + index = idx;
98 + return idx;
99 + }
100 + }
101 + }
102 + });
103 +
104 + return index;
105 +}
106 +
107 +/**
108 + * 배열 안의 요소 중에서 파라미터와 같은 객체를 리턴
109 + */
110 +function findByParam(arr, obj, callback) {
111 + var index = exports.indexof(arr, obj)
112 + if (~index && typeof callback === 'function') {
113 + return callback(undefined, arr[index])
114 + } else if (~index && !callback) {
115 + return arr[index]
116 + } else if (!~index && typeof callback === 'function') {
117 + return callback('not found')
118 + }
119 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -10,7 +10,7 @@ Schema.createSchema = function(mongoose) { ...@@ -10,7 +10,7 @@ Schema.createSchema = function(mongoose) {
10 hashed_password: {type: String, required: true, 'default':''}, 10 hashed_password: {type: String, required: true, 'default':''},
11 salt: {type:String, required:true}, 11 salt: {type:String, required:true},
12 name: {type: String, index: 'hashed', 'default':''}, 12 name: {type: String, index: 'hashed', 'default':''},
13 - age: {type: Number, 'default': -1}, 13 + email: {type: Number, 'default': ''},
14 created_at: {type: Date, index: {unique: false}, 'default': Date.now}, 14 created_at: {type: Date, index: {unique: false}, 'default': Date.now},
15 updated_at: {type: Date, index: {unique: false}, 'default': Date.now} 15 updated_at: {type: Date, index: {unique: false}, 'default': Date.now}
16 }); 16 });
...@@ -91,8 +91,6 @@ Schema.createSchema = function(mongoose) { ...@@ -91,8 +91,6 @@ Schema.createSchema = function(mongoose) {
91 return this.find({}, callback); 91 return this.find({}, callback);
92 }); 92 });
93 93
94 - console.log('UserSchema 정의함.');
95 -
96 return UserSchema; 94 return UserSchema;
97 }; 95 };
98 96
......
1 +
2 +var express = require('express')
3 +var router = express.Router()
4 +var Entities = require('html-entities').AllHtmlEntities;
5 +
6 +router.get('/',function(req,res){
7 + var paramPage = 0;
8 + var paramPerPage = 10;
9 +
10 + var database = req.app.get('database');
11 +
12 + // 데이터베이스 객체가 초기화된 경우
13 + if (database.db) {
14 + // 1. 글 리스트
15 + var options = {
16 + page: paramPage,
17 + perPage: paramPerPage
18 + }
19 +
20 + database.PostModel.list(options, function(err, results) {
21 + if (err) {
22 + console.error('게시판 글 목록 조회 중 에러 발생 : ' + err.stack);
23 +
24 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
25 + res.write('<h2>게시판 글 목록 조회 중 에러 발생</h2>');
26 + res.write('<p>' + err.stack + '</p>');
27 + res.end();
28 +
29 + return;
30 + }
31 +
32 + if (results) {
33 + console.dir(results);
34 +
35 + // 전체 문서 객체 수 확인
36 + database.PostModel.count().exec(function(err, count) {
37 +
38 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
39 +
40 + // 뷰 템플레이트를 이용하여 렌더링한 후 전송
41 + var context = {
42 + title: '글 목록',
43 + posts: results,
44 + page: parseInt(paramPage),
45 + pageCount: Math.ceil(count / paramPerPage),
46 + perPage: paramPerPage,
47 + totalRecords: count,
48 + size: paramPerPage
49 + };
50 + req.app.render('post', context, function(err, html) {
51 + if (err) {
52 + console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
53 +
54 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
55 + res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
56 + res.write('<p>' + err.stack + '</p>');
57 + res.end();
58 +
59 + return;
60 + }
61 +
62 + res.end(html);
63 + });
64 +
65 + });
66 +
67 + } else {
68 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
69 + res.write('<h2>글 목록 조회 실패</h2>');
70 + res.end();
71 + }
72 + });
73 + } else {
74 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
75 + res.write('<h2>데이터베이스 연결 실패</h2>');
76 + res.end();
77 + }
78 +
79 +})
80 +
81 +module.exports = router;
82 +// var addpost = function(req, res) {
83 +// console.log('post 모듈 안에 있는 addpost 호출됨.');
84 +
85 +// var paramTitle = req.body.title || req.query.title;
86 +// var paramContents = req.body.contents || req.query.contents;
87 +// var paramWriter = req.body.writer || req.query.writer;
88 +
89 +// console.log('요청 파라미터 : ' + paramTitle + ', ' + paramContents + ', ' +
90 +// paramWriter);
91 +
92 +// var database = req.app.get('database');
93 +
94 +// // 데이터베이스 객체가 초기화된 경우
95 +// if (database.db) {
96 +
97 +// // 1. 아이디를 이용해 사용자 검색
98 +// database.UserModel.findByEmail(paramWriter, function(err, results) {
99 +// if (err) {
100 +// console.error('게시판 글 추가 중 에러 발생 : ' + err.stack);
101 +
102 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
103 +// res.write('<h2>게시판 글 추가 중 에러 발생</h2>');
104 +// res.write('<p>' + err.stack + '</p>');
105 +// res.end();
106 +
107 +// return;
108 +// }
109 +
110 +// if (results == undefined || results.length < 1) {
111 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
112 +// res.write('<h2>사용자 [' + paramWriter + ']를 찾을 수 없습니다.</h2>');
113 +// res.end();
114 +
115 +// return;
116 +// }
117 +
118 +// var userObjectId = results[0]._doc._id;
119 +// console.log('사용자 ObjectId : ' + paramWriter +' -> ' + userObjectId);
120 +
121 +// // save()로 저장
122 +// // PostModel 인스턴스 생성
123 +// var post = new database.PostModel({
124 +// title: paramTitle,
125 +// contents: paramContents,
126 +// writer: userObjectId
127 +// });
128 +
129 +// post.savePost(function(err, result) {
130 +// if (err) {
131 +// if (err) {
132 +// console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
133 +
134 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
135 +// res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
136 +// res.write('<p>' + err.stack + '</p>');
137 +// res.end();
138 +
139 +// return;
140 +// }
141 +// }
142 +
143 +// console.log("글 데이터 추가함.");
144 +// console.log('글 작성', '포스팅 글을 생성했습니다. : ' + post._id);
145 +
146 +// return res.redirect('/process/showpost/' + post._id);
147 +// });
148 +
149 +// });
150 +
151 +// } else {
152 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
153 +// res.write('<h2>데이터베이스 연결 실패</h2>');
154 +// res.end();
155 +// }
156 +
157 +// };
158 +
159 +// var listpost = function(req, res) {
160 +// console.log('post 모듈 안에 있는 listpost 호출됨.');
161 +
162 +// var paramPage = req.body.page || req.query.page;
163 +// var paramPerPage = req.body.perPage || req.query.perPage;
164 +
165 +// console.log('요청 파라미터 : ' + paramPage + ', ' + paramPerPage);
166 +
167 +// var database = req.app.get('database');
168 +
169 +// // 데이터베이스 객체가 초기화된 경우
170 +// if (database.db) {
171 +// // 1. 글 리스트
172 +// var options = {
173 +// page: paramPage,
174 +// perPage: paramPerPage
175 +// }
176 +
177 +// database.PostModel.list(options, function(err, results) {
178 +// if (err) {
179 +// console.error('게시판 글 목록 조회 중 에러 발생 : ' + err.stack);
180 +
181 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
182 +// res.write('<h2>게시판 글 목록 조회 중 에러 발생</h2>');
183 +// res.write('<p>' + err.stack + '</p>');
184 +// res.end();
185 +
186 +// return;
187 +// }
188 +
189 +// if (results) {
190 +// console.dir(results);
191 +
192 +// // 전체 문서 객체 수 확인
193 +// database.PostModel.count().exec(function(err, count) {
194 +
195 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
196 +
197 +// // 뷰 템플레이트를 이용하여 렌더링한 후 전송
198 +// var context = {
199 +// title: '글 목록',
200 +// posts: results,
201 +// page: parseInt(paramPage),
202 +// pageCount: Math.ceil(count / paramPerPage),
203 +// perPage: paramPerPage,
204 +// totalRecords: count,
205 +// size: paramPerPage
206 +// };
207 +
208 +// req.app.render('listpost', context, function(err, html) {
209 +// if (err) {
210 +// console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
211 +
212 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
213 +// res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
214 +// res.write('<p>' + err.stack + '</p>');
215 +// res.end();
216 +
217 +// return;
218 +// }
219 +
220 +// res.end(html);
221 +// });
222 +
223 +// });
224 +
225 +// } else {
226 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
227 +// res.write('<h2>글 목록 조회 실패</h2>');
228 +// res.end();
229 +// }
230 +// });
231 +// } else {
232 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
233 +// res.write('<h2>데이터베이스 연결 실패</h2>');
234 +// res.end();
235 +// }
236 +
237 +// };
238 +
239 +
240 +// var showpost = function(req, res) {
241 +// console.log('post 모듈 안에 있는 showpost 호출됨.');
242 +
243 +// // URL 파라미터로 전달됨
244 +// var paramId = req.body.id || req.query.id || req.params.id;
245 +
246 +// console.log('요청 파라미터 : ' + paramId);
247 +
248 +
249 +// var database = req.app.get('database');
250 +
251 +// // 데이터베이스 객체가 초기화된 경우
252 +// if (database.db) {
253 +// // 1. 글 리스트
254 +// database.PostModel.load(paramId, function(err, results) {
255 +// if (err) {
256 +// console.error('게시판 글 조회 중 에러 발생 : ' + err.stack);
257 +
258 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
259 +// res.write('<h2>게시판 글 조회 중 에러 발생</h2>');
260 +// res.write('<p>' + err.stack + '</p>');
261 +// res.end();
262 +
263 +// return;
264 +// }
265 +
266 +// if (results) {
267 +// console.dir(results);
268 +
269 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
270 +
271 +// // 뷰 템플레이트를 이용하여 렌더링한 후 전송
272 +// var context = {
273 +// title: '글 조회 ',
274 +// posts: results,
275 +// Entities: Entities
276 +// };
277 +
278 +// req.app.render('showpost', context, function(err, html) {
279 +// if (err) {
280 +// console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
281 +
282 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
283 +// res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
284 +// res.write('<p>' + err.stack + '</p>');
285 +// res.end();
286 +
287 +// return;
288 +// }
289 +
290 +// console.log('응답 웹문서 : ' + html);
291 +// res.end(html);
292 +// });
293 +
294 +// } else {
295 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
296 +// res.write('<h2>글 조회 실패</h2>');
297 +// res.end();
298 +// }
299 +// });
300 +// } else {
301 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
302 +// res.write('<h2>데이터베이스 연결 실패</h2>');
303 +// res.end();
304 +// }
305 +
306 +// };
307 +
308 +// module.exports.listpost = listpost;
309 +// module.exports.addpost = addpost;
310 +// module.exports.showpost = showpost;
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +var express = require('express')
3 +var router = express.Router()
4 +var Entities = require('html-entities').AllHtmlEntities;
5 +
6 +router.get('/',function(req,res){
7 + res.render('postadd.ejs');
8 +})
9 +
10 +module.exports = router;
11 +// var addpost = function(req, res) {
12 +// console.log('post 모듈 안에 있는 addpost 호출됨.');
13 +
14 +// var paramTitle = req.body.title || req.query.title;
15 +// var paramContents = req.body.contents || req.query.contents;
16 +// var paramWriter = req.body.writer || req.query.writer;
17 +
18 +// console.log('요청 파라미터 : ' + paramTitle + ', ' + paramContents + ', ' +
19 +// paramWriter);
20 +
21 +// var database = req.app.get('database');
22 +
23 +// // 데이터베이스 객체가 초기화된 경우
24 +// if (database.db) {
25 +
26 +// // 1. 아이디를 이용해 사용자 검색
27 +// database.UserModel.findByEmail(paramWriter, function(err, results) {
28 +// if (err) {
29 +// console.error('게시판 글 추가 중 에러 발생 : ' + err.stack);
30 +
31 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
32 +// res.write('<h2>게시판 글 추가 중 에러 발생</h2>');
33 +// res.write('<p>' + err.stack + '</p>');
34 +// res.end();
35 +
36 +// return;
37 +// }
38 +
39 +// if (results == undefined || results.length < 1) {
40 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
41 +// res.write('<h2>사용자 [' + paramWriter + ']를 찾을 수 없습니다.</h2>');
42 +// res.end();
43 +
44 +// return;
45 +// }
46 +
47 +// var userObjectId = results[0]._doc._id;
48 +// console.log('사용자 ObjectId : ' + paramWriter +' -> ' + userObjectId);
49 +
50 +// // save()로 저장
51 +// // PostModel 인스턴스 생성
52 +// var post = new database.PostModel({
53 +// title: paramTitle,
54 +// contents: paramContents,
55 +// writer: userObjectId
56 +// });
57 +
58 +// post.savePost(function(err, result) {
59 +// if (err) {
60 +// if (err) {
61 +// console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
62 +
63 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
64 +// res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
65 +// res.write('<p>' + err.stack + '</p>');
66 +// res.end();
67 +
68 +// return;
69 +// }
70 +// }
71 +
72 +// console.log("글 데이터 추가함.");
73 +// console.log('글 작성', '포스팅 글을 생성했습니다. : ' + post._id);
74 +
75 +// return res.redirect('/process/showpost/' + post._id);
76 +// });
77 +
78 +// });
79 +
80 +// } else {
81 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
82 +// res.write('<h2>데이터베이스 연결 실패</h2>');
83 +// res.end();
84 +// }
85 +
86 +// };
87 +
88 +// var listpost = function(req, res) {
89 +// console.log('post 모듈 안에 있는 listpost 호출됨.');
90 +
91 +// var paramPage = req.body.page || req.query.page;
92 +// var paramPerPage = req.body.perPage || req.query.perPage;
93 +
94 +// console.log('요청 파라미터 : ' + paramPage + ', ' + paramPerPage);
95 +
96 +// var database = req.app.get('database');
97 +
98 +// // 데이터베이스 객체가 초기화된 경우
99 +// if (database.db) {
100 +// // 1. 글 리스트
101 +// var options = {
102 +// page: paramPage,
103 +// perPage: paramPerPage
104 +// }
105 +
106 +// database.PostModel.list(options, function(err, results) {
107 +// if (err) {
108 +// console.error('게시판 글 목록 조회 중 에러 발생 : ' + err.stack);
109 +
110 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
111 +// res.write('<h2>게시판 글 목록 조회 중 에러 발생</h2>');
112 +// res.write('<p>' + err.stack + '</p>');
113 +// res.end();
114 +
115 +// return;
116 +// }
117 +
118 +// if (results) {
119 +// console.dir(results);
120 +
121 +// // 전체 문서 객체 수 확인
122 +// database.PostModel.count().exec(function(err, count) {
123 +
124 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
125 +
126 +// // 뷰 템플레이트를 이용하여 렌더링한 후 전송
127 +// var context = {
128 +// title: '글 목록',
129 +// posts: results,
130 +// page: parseInt(paramPage),
131 +// pageCount: Math.ceil(count / paramPerPage),
132 +// perPage: paramPerPage,
133 +// totalRecords: count,
134 +// size: paramPerPage
135 +// };
136 +
137 +// req.app.render('listpost', context, function(err, html) {
138 +// if (err) {
139 +// console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
140 +
141 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
142 +// res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
143 +// res.write('<p>' + err.stack + '</p>');
144 +// res.end();
145 +
146 +// return;
147 +// }
148 +
149 +// res.end(html);
150 +// });
151 +
152 +// });
153 +
154 +// } else {
155 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
156 +// res.write('<h2>글 목록 조회 실패</h2>');
157 +// res.end();
158 +// }
159 +// });
160 +// } else {
161 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
162 +// res.write('<h2>데이터베이스 연결 실패</h2>');
163 +// res.end();
164 +// }
165 +
166 +// };
167 +
168 +
169 +// var showpost = function(req, res) {
170 +// console.log('post 모듈 안에 있는 showpost 호출됨.');
171 +
172 +// // URL 파라미터로 전달됨
173 +// var paramId = req.body.id || req.query.id || req.params.id;
174 +
175 +// console.log('요청 파라미터 : ' + paramId);
176 +
177 +
178 +// var database = req.app.get('database');
179 +
180 +// // 데이터베이스 객체가 초기화된 경우
181 +// if (database.db) {
182 +// // 1. 글 리스트
183 +// database.PostModel.load(paramId, function(err, results) {
184 +// if (err) {
185 +// console.error('게시판 글 조회 중 에러 발생 : ' + err.stack);
186 +
187 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
188 +// res.write('<h2>게시판 글 조회 중 에러 발생</h2>');
189 +// res.write('<p>' + err.stack + '</p>');
190 +// res.end();
191 +
192 +// return;
193 +// }
194 +
195 +// if (results) {
196 +// console.dir(results);
197 +
198 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
199 +
200 +// // 뷰 템플레이트를 이용하여 렌더링한 후 전송
201 +// var context = {
202 +// title: '글 조회 ',
203 +// posts: results,
204 +// Entities: Entities
205 +// };
206 +
207 +// req.app.render('showpost', context, function(err, html) {
208 +// if (err) {
209 +// console.error('응답 웹문서 생성 중 에러 발생 : ' + err.stack);
210 +
211 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
212 +// res.write('<h2>응답 웹문서 생성 중 에러 발생</h2>');
213 +// res.write('<p>' + err.stack + '</p>');
214 +// res.end();
215 +
216 +// return;
217 +// }
218 +
219 +// console.log('응답 웹문서 : ' + html);
220 +// res.end(html);
221 +// });
222 +
223 +// } else {
224 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
225 +// res.write('<h2>글 조회 실패</h2>');
226 +// res.end();
227 +// }
228 +// });
229 +// } else {
230 +// res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
231 +// res.write('<h2>데이터베이스 연결 실패</h2>');
232 +// res.end();
233 +// }
234 +
235 +// };
236 +
237 +// module.exports.listpost = listpost;
238 +// module.exports.addpost = addpost;
239 +// module.exports.showpost = showpost;
...\ No newline at end of file ...\ No newline at end of file
...@@ -9,14 +9,14 @@ router.get('/',function(req,res){ ...@@ -9,14 +9,14 @@ router.get('/',function(req,res){
9 router.post('/process', function(req, res) { 9 router.post('/process', function(req, res) {
10 console.log('/signup/process 처리함'); 10 console.log('/signup/process 처리함');
11 11
12 - var paramName = req.body.name || req.query.name; 12 + var paramEmail = req.body.email || req.query.email;
13 var paramId = req.body.id || req.query.id; 13 var paramId = req.body.id || req.query.id;
14 var paramPassword = req.body.password || req.query.password; 14 var paramPassword = req.body.password || req.query.password;
15 //GET, POST 모두 고려해서 둘 다 검사 15 //GET, POST 모두 고려해서 둘 다 검사
16 16
17 res.writeHead('200', { 'Content-Type': 'text/html;charset=utf8' }); 17 res.writeHead('200', { 'Content-Type': 'text/html;charset=utf8' });
18 res.write('<h1>Result form Express Server</h1>'); 18 res.write('<h1>Result form Express Server</h1>');
19 - res.write('<div><p>Param name : ' + paramName + '</p></div>'); 19 + res.write('<div><p>Param E-mail : ' + paramEmail + '</p></div>');
20 res.write('<div><p>Param id : ' + paramId + '</p></div>'); 20 res.write('<div><p>Param id : ' + paramId + '</p></div>');
21 res.write('<div><p>Param password : ' + paramPassword + '</p></div>'); 21 res.write('<div><p>Param password : ' + paramPassword + '</p></div>');
22 res.write("<br><br><a href ='/login.html'>로그인 페이지로 돌아가기</a>"); 22 res.write("<br><br><a href ='/login.html'>로그인 페이지로 돌아가기</a>");
......
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +
4 +<head>
5 + <meta charset="utf-8" />
6 + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
7 + <meta name="description" content="" />
8 + <meta name="author" content="" />
9 + <title>Modern Business - Start Bootstrap Template</title>
10 + <!-- Favicon-->
11 + <link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
12 + <!-- Bootstrap icons-->
13 + <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
14 + <!-- Core theme CSS (includes Bootstrap)-->
15 + <link href="css/styles.css" rel="stylesheet" />
16 + <script src="http://code.jquery.com/jquery-2.1.4.js"></script>
17 +</head>
18 +
19 +<body class="d-flex flex-column h-100">
20 + <main class="flex-shrink-0">
21 + <!-- Navigation-->
22 + <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
23 + <div class="container px-5">
24 + <a class="navbar-brand" href="/">휴게소 정보</a>
25 + <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
26 + data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
27 + aria-expanded="false" aria-label="Toggle navigation"><span
28 + class="navbar-toggler-icon"></span></button>
29 + <div class="collapse navbar-collapse" id="navbarSupportedContent">
30 + <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
31 + <li class="nav-item"><a class="nav-link" href="/">Home</a></li>
32 + <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
33 + <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
34 + <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
35 + <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li>
36 + <li class="nav-item dropdown">
37 + <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button"
38 + data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
39 + <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
40 + <li><a class="dropdown-item" href="blog-home.html">Blog Home</a></li>
41 + <li><a class="dropdown-item" href="blog-post.html">Blog Post</a></li>
42 + </ul>
43 + </li>
44 + <li class="nav-item dropdown">
45 + <a class="nav-link dropdown-toggle" id="navbarDropdownLogin" href="#" role="button"
46 + data-bs-toggle="dropdown" aria-expanded="false">Login</a>
47 + <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownLogin">
48 + <li><a class="dropdown-item" href="/login">Login</a></li>
49 + <li><a class="dropdown-item" href="/signup">Sign-up</a></li>
50 + </ul>
51 + </li>
52 + </ul>
53 + </div>
54 + </div>
55 + </nav>
56 + <!-- Page Content-->
57 + <div class="container">
58 + <br>
59 +
60 + <div class="ui raised segment">
61 + <a class="ui blue ribbon label">게시판</a>
62 +
63 +
64 + <div class="ui blue fluid card">
65 + <div class="content">
66 + <table border="1" width="800" align="center">
67 + <tr align="center">
68 + <p>
69 + <td colspan="3">게시판</td>
70 + </p>
71 + </tr>
72 + <tr align="center">
73 + <td>번호</td>
74 + <td>제목</td>
75 + <td>작성자</td>
76 + <td>작성일</td>
77 + </tr>
78 + <div class="ui very relaxed selection celled list">
79 + <% var noStart = 4; for(var i=0; i < posts.length; i++){ var curTitle=posts[i]._doc.title;
80 + var curNo=noStart - i; var createdDate = posts[i]._doc.created_at; %>
81 + <tr align="center">
82 + <td>
83 + <%= curNo %>
84 + </td>
85 + <td>
86 + <%= curTitle %>
87 + </td>
88 + <td>admin</td>
89 + <td><%=createdDate%></td>
90 + </tr>
91 + <% } %>
92 + </div>
93 + </table>
94 +
95 +
96 +
97 +
98 + <br><br>
99 + <a class="ui button" href='/postadd'>글쓰기</a>
100 +
101 + </div>
102 + </div>
103 + </div>
104 + </div>
105 + </main>
106 + <!-- Footer-->
107 + <footer class="bg-dark py-4 mt-auto">
108 + <div class="container px-5">
109 + <div class="row align-items-center justify-content-between flex-column flex-sm-row">
110 + <div class="col-auto">
111 + <div class="small m-0 text-white">Copyright &copy; Your Website 2022</div>
112 + </div>
113 + <div class="col-auto">
114 + <a class="link-light small" href="#!">Privacy</a>
115 + <span class="text-white mx-1">&middot;</span>
116 + <a class="link-light small" href="#!">Terms</a>
117 + <span class="text-white mx-1">&middot;</span>
118 + <a class="link-light small" href="#!">Contact</a>
119 + </div>
120 + </div>
121 + </div>
122 + </footer>
123 + <!-- Bootstrap core JS-->
124 + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
125 + <!-- Core theme JS-->
126 + <script src="js/scripts.js"></script>
127 +</body>
128 +
129 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +
4 +<head>
5 + <meta charset="utf-8" />
6 + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
7 + <meta name="description" content="" />
8 + <meta name="author" content="" />
9 + <title>Modern Business - Start Bootstrap Template</title>
10 + <!-- Favicon-->
11 + <link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
12 + <!-- Bootstrap icons-->
13 + <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
14 + <!-- Core theme CSS (includes Bootstrap)-->
15 + <link href="css/styles.css" rel="stylesheet" />
16 + <script src="http://code.jquery.com/jquery-2.1.4.js"></script>
17 +</head>
18 +
19 +<body class="d-flex flex-column h-100">
20 + <main class="flex-shrink-0">
21 + <!-- Navigation-->
22 + <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
23 + <div class="container px-5">
24 + <a class="navbar-brand" href="/">휴게소 정보</a>
25 + <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
26 + data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
27 + aria-expanded="false" aria-label="Toggle navigation"><span
28 + class="navbar-toggler-icon"></span></button>
29 + <div class="collapse navbar-collapse" id="navbarSupportedContent">
30 + <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
31 + <li class="nav-item"><a class="nav-link" href="/">Home</a></li>
32 + <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
33 + <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
34 + <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
35 + <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li>
36 + <li class="nav-item dropdown">
37 + <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button"
38 + data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
39 + <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
40 + <li><a class="dropdown-item" href="blog-home.html">Blog Home</a></li>
41 + <li><a class="dropdown-item" href="blog-post.html">Blog Post</a></li>
42 + </ul>
43 + </li>
44 + <li class="nav-item dropdown">
45 + <a class="nav-link dropdown-toggle" id="navbarDropdownLogin" href="#" role="button"
46 + data-bs-toggle="dropdown" aria-expanded="false">Login</a>
47 + <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownLogin">
48 + <li><a class="dropdown-item" href="/login">Login</a></li>
49 + <li><a class="dropdown-item" href="/signup">Sign-up</a></li>
50 + </ul>
51 + </li>
52 + </ul>
53 + </div>
54 + </div>
55 + </nav>
56 + <!-- Page Content-->
57 + <div class="container">
58 + <br>
59 +
60 + <div class="ui raised segment">
61 + <a class="ui blue ribbon label">게시판</a>
62 +
63 +
64 + <div class="ui blue fluid card">
65 + <div class="content">
66 + <br><br>
67 + <a class="ui button" href='/postadd'>글쓰기</a>
68 +
69 + </div>
70 + </div>
71 + </div>
72 + </div>
73 + </main>
74 + <!-- Footer-->
75 + <footer class="bg-dark py-4 mt-auto">
76 + <div class="container px-5">
77 + <div class="row align-items-center justify-content-between flex-column flex-sm-row">
78 + <div class="col-auto">
79 + <div class="small m-0 text-white">Copyright &copy; Your Website 2022</div>
80 + </div>
81 + <div class="col-auto">
82 + <a class="link-light small" href="#!">Privacy</a>
83 + <span class="text-white mx-1">&middot;</span>
84 + <a class="link-light small" href="#!">Terms</a>
85 + <span class="text-white mx-1">&middot;</span>
86 + <a class="link-light small" href="#!">Contact</a>
87 + </div>
88 + </div>
89 + </div>
90 + </footer>
91 + <!-- Bootstrap core JS-->
92 + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
93 + <!-- Core theme JS-->
94 + <script src="js/scripts.js"></script>
95 +</body>
96 +
97 +</html>
...\ No newline at end of file ...\ No newline at end of file
...@@ -58,8 +58,8 @@ ...@@ -58,8 +58,8 @@
58 <form method="post" action="/signup/process"> 58 <form method="post" action="/signup/process">
59 <table> 59 <table>
60 <tr> 60 <tr>
61 - <td><label>이름</label></td> 61 + <td><label>E-mail</label></td>
62 - <td><input type="text" name="name"></td> 62 + <td><input type="text" name="email"></td>
63 </tr> 63 </tr>
64 <tr> 64 <tr>
65 <td><label>아이디</label></td> 65 <td><label>아이디</label></td>
......
1 -#!/bin/sh 1 +../ejs/bin/cli.js
2 -basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 -
4 -case `uname` in
5 - *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 -esac
7 -
8 -if [ -x "$basedir/node" ]; then
9 - exec "$basedir/node" "$basedir/../ejs/bin/cli.js" "$@"
10 -else
11 - exec node "$basedir/../ejs/bin/cli.js" "$@"
12 -fi
...\ No newline at end of file ...\ No newline at end of file
......
1 -#!/bin/sh 1 +../jake/bin/cli.js
2 -basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 -
4 -case `uname` in
5 - *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 -esac
7 -
8 -if [ -x "$basedir/node" ]; then
9 - exec "$basedir/node" "$basedir/../jake/bin/cli.js" "$@"
10 -else
11 - exec node "$basedir/../jake/bin/cli.js" "$@"
12 -fi
...\ No newline at end of file ...\ No newline at end of file
......
1 -#!/bin/sh 1 +../mime/cli.js
2 -basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3 -
4 -case `uname` in
5 - *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6 -esac
7 -
8 -if [ -x "$basedir/node" ]; then
9 - exec "$basedir/node" "$basedir/../mime/cli.js" "$@"
10 -else
11 - exec node "$basedir/../mime/cli.js" "$@"
12 -fi
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -337,9 +337,9 @@ ...@@ -337,9 +337,9 @@
337 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 337 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
338 }, 338 },
339 "node_modules/ejs": { 339 "node_modules/ejs": {
340 - "version": "3.1.7", 340 + "version": "3.1.8",
341 - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz", 341 + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
342 - "integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==", 342 + "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
343 "dependencies": { 343 "dependencies": {
344 "jake": "^10.8.5" 344 "jake": "^10.8.5"
345 }, 345 },
...@@ -554,6 +554,11 @@ ...@@ -554,6 +554,11 @@
554 "url": "https://github.com/sponsors/ljharb" 554 "url": "https://github.com/sponsors/ljharb"
555 } 555 }
556 }, 556 },
557 + "node_modules/html-entities": {
558 + "version": "2.3.3",
559 + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.3.3.tgz",
560 + "integrity": "sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA=="
561 + },
557 "node_modules/http": { 562 "node_modules/http": {
558 "version": "0.0.1-security", 563 "version": "0.0.1-security",
559 "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", 564 "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
......
...@@ -55,6 +55,9 @@ for all the passed options. However, be aware that your code could break if we ...@@ -55,6 +55,9 @@ for all the passed options. However, be aware that your code could break if we
55 add an option with the same name as one of your data object's properties. 55 add an option with the same name as one of your data object's properties.
56 Therefore, we do not recommend using this shortcut. 56 Therefore, we do not recommend using this shortcut.
57 57
58 +### Important
59 +You should never give end-users unfettered access to the EJS render method, If you do so you are using EJS in an inherently un-secure way.
60 +
58 ### Options 61 ### Options
59 62
60 - `cache` Compiled functions are cached, requires `filename` 63 - `cache` Compiled functions are cached, requires `filename`
......
...@@ -979,6 +979,8 @@ if (typeof window != 'undefined') { ...@@ -979,6 +979,8 @@ if (typeof window != 'undefined') {
979 'use strict'; 979 'use strict';
980 980
981 var regExpChars = /[|\\{}()[\]^$+*?.]/g; 981 var regExpChars = /[|\\{}()[\]^$+*?.]/g;
982 +var hasOwnProperty = Object.prototype.hasOwnProperty;
983 +var hasOwn = function (obj, key) { return hasOwnProperty.apply(obj, [key]); };
982 984
983 /** 985 /**
984 * Escape characters reserved in regular expressions. 986 * Escape characters reserved in regular expressions.
...@@ -1070,6 +1072,12 @@ exports.shallowCopy = function (to, from) { ...@@ -1070,6 +1072,12 @@ exports.shallowCopy = function (to, from) {
1070 from = from || {}; 1072 from = from || {};
1071 if ((to !== null) && (to !== undefined)) { 1073 if ((to !== null) && (to !== undefined)) {
1072 for (var p in from) { 1074 for (var p in from) {
1075 + if (!hasOwn(from, p)) {
1076 + continue;
1077 + }
1078 + if (p === '__proto__' || p === 'constructor') {
1079 + continue;
1080 + }
1073 to[p] = from[p]; 1081 to[p] = from[p];
1074 } 1082 }
1075 } 1083 }
...@@ -1095,6 +1103,12 @@ exports.shallowCopyFromList = function (to, from, list) { ...@@ -1095,6 +1103,12 @@ exports.shallowCopyFromList = function (to, from, list) {
1095 for (var i = 0; i < list.length; i++) { 1103 for (var i = 0; i < list.length; i++) {
1096 var p = list[i]; 1104 var p = list[i];
1097 if (typeof from[p] != 'undefined') { 1105 if (typeof from[p] != 'undefined') {
1106 + if (!hasOwn(from, p)) {
1107 + continue;
1108 + }
1109 + if (p === '__proto__' || p === 'constructor') {
1110 + continue;
1111 + }
1098 to[p] = from[p]; 1112 to[p] = from[p];
1099 } 1113 }
1100 } 1114 }
...@@ -1667,7 +1681,7 @@ module.exports={ ...@@ -1667,7 +1681,7 @@ module.exports={
1667 "engine", 1681 "engine",
1668 "ejs" 1682 "ejs"
1669 ], 1683 ],
1670 - "version": "3.1.6", 1684 + "version": "3.1.7",
1671 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)", 1685 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
1672 "license": "Apache-2.0", 1686 "license": "Apache-2.0",
1673 "bin": { 1687 "bin": {
......
This diff is collapsed. Click to expand it.
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
25 'use strict'; 25 'use strict';
26 26
27 var regExpChars = /[|\\{}()[\]^$+*?.]/g; 27 var regExpChars = /[|\\{}()[\]^$+*?.]/g;
28 +var hasOwnProperty = Object.prototype.hasOwnProperty;
29 +var hasOwn = function (obj, key) { return hasOwnProperty.apply(obj, [key]); };
28 30
29 /** 31 /**
30 * Escape characters reserved in regular expressions. 32 * Escape characters reserved in regular expressions.
...@@ -116,6 +118,12 @@ exports.shallowCopy = function (to, from) { ...@@ -116,6 +118,12 @@ exports.shallowCopy = function (to, from) {
116 from = from || {}; 118 from = from || {};
117 if ((to !== null) && (to !== undefined)) { 119 if ((to !== null) && (to !== undefined)) {
118 for (var p in from) { 120 for (var p in from) {
121 + if (!hasOwn(from, p)) {
122 + continue;
123 + }
124 + if (p === '__proto__' || p === 'constructor') {
125 + continue;
126 + }
119 to[p] = from[p]; 127 to[p] = from[p];
120 } 128 }
121 } 129 }
...@@ -141,6 +149,12 @@ exports.shallowCopyFromList = function (to, from, list) { ...@@ -141,6 +149,12 @@ exports.shallowCopyFromList = function (to, from, list) {
141 for (var i = 0; i < list.length; i++) { 149 for (var i = 0; i < list.length; i++) {
142 var p = list[i]; 150 var p = list[i];
143 if (typeof from[p] != 'undefined') { 151 if (typeof from[p] != 'undefined') {
152 + if (!hasOwn(from, p)) {
153 + continue;
154 + }
155 + if (p === '__proto__' || p === 'constructor') {
156 + continue;
157 + }
144 to[p] = from[p]; 158 to[p] = from[p];
145 } 159 }
146 } 160 }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
6 "engine", 6 "engine",
7 "ejs" 7 "ejs"
8 ], 8 ],
9 - "version": "3.1.7", 9 + "version": "3.1.8",
10 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)", 10 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
11 "license": "Apache-2.0", 11 "license": "Apache-2.0",
12 "bin": { 12 "bin": {
......
...@@ -13,10 +13,11 @@ ...@@ -13,10 +13,11 @@
13 "bootstrap": "^5.1.3", 13 "bootstrap": "^5.1.3",
14 "cookie-parser": "^1.4.6", 14 "cookie-parser": "^1.4.6",
15 "crypto": "^1.0.1", 15 "crypto": "^1.0.1",
16 - "ejs": "^3.1.7", 16 + "ejs": "^3.1.8",
17 "express": "^4.18.1", 17 "express": "^4.18.1",
18 "express-error-handler": "^1.1.0", 18 "express-error-handler": "^1.1.0",
19 "express-session": "^1.17.3", 19 "express-session": "^1.17.3",
20 + "html-entities": "^2.3.3",
20 "http": "^0.0.1-security", 21 "http": "^0.0.1-security",
21 "mongoose": "^6.3.4", 22 "mongoose": "^6.3.4",
22 "mysql": "^2.18.1", 23 "mysql": "^2.18.1",
...@@ -357,9 +358,9 @@ ...@@ -357,9 +358,9 @@
357 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 358 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
358 }, 359 },
359 "node_modules/ejs": { 360 "node_modules/ejs": {
360 - "version": "3.1.7", 361 + "version": "3.1.8",
361 - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz", 362 + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
362 - "integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==", 363 + "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
363 "dependencies": { 364 "dependencies": {
364 "jake": "^10.8.5" 365 "jake": "^10.8.5"
365 }, 366 },
...@@ -574,6 +575,11 @@ ...@@ -574,6 +575,11 @@
574 "url": "https://github.com/sponsors/ljharb" 575 "url": "https://github.com/sponsors/ljharb"
575 } 576 }
576 }, 577 },
578 + "node_modules/html-entities": {
579 + "version": "2.3.3",
580 + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.3.3.tgz",
581 + "integrity": "sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA=="
582 + },
577 "node_modules/http": { 583 "node_modules/http": {
578 "version": "0.0.1-security", 584 "version": "0.0.1-security",
579 "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", 585 "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
...@@ -1526,9 +1532,9 @@ ...@@ -1526,9 +1532,9 @@
1526 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 1532 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
1527 }, 1533 },
1528 "ejs": { 1534 "ejs": {
1529 - "version": "3.1.7", 1535 + "version": "3.1.8",
1530 - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz", 1536 + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
1531 - "integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==", 1537 + "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
1532 "requires": { 1538 "requires": {
1533 "jake": "^10.8.5" 1539 "jake": "^10.8.5"
1534 } 1540 }
...@@ -1699,6 +1705,11 @@ ...@@ -1699,6 +1705,11 @@
1699 "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", 1705 "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
1700 "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" 1706 "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
1701 }, 1707 },
1708 + "html-entities": {
1709 + "version": "2.3.3",
1710 + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.3.3.tgz",
1711 + "integrity": "sha512-DV5Ln36z34NNTDgnz0EWGBLZENelNAtkiFA4kyNOG2tDI6Mz1uSWiq1wAKdyjnJwyDiDO7Fa2SO1CTxPXL8VxA=="
1712 + },
1702 "http": { 1713 "http": {
1703 "version": "0.0.1-security", 1714 "version": "0.0.1-security",
1704 "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", 1715 "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
......
...@@ -13,10 +13,11 @@ ...@@ -13,10 +13,11 @@
13 "bootstrap": "^5.1.3", 13 "bootstrap": "^5.1.3",
14 "cookie-parser": "^1.4.6", 14 "cookie-parser": "^1.4.6",
15 "crypto": "^1.0.1", 15 "crypto": "^1.0.1",
16 - "ejs": "^3.1.7", 16 + "ejs": "^3.1.8",
17 "express": "^4.18.1", 17 "express": "^4.18.1",
18 "express-error-handler": "^1.1.0", 18 "express-error-handler": "^1.1.0",
19 "express-session": "^1.17.3", 19 "express-session": "^1.17.3",
20 + "html-entities": "^2.3.3",
20 "http": "^0.0.1-security", 21 "http": "^0.0.1-security",
21 "mongoose": "^6.3.4", 22 "mongoose": "^6.3.4",
22 "mysql": "^2.18.1", 23 "mysql": "^2.18.1",
......