diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..cbb5cde
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.DS_STORE/
+.idea/
+*.log
+.project
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 7c62b52..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/.idea/libraries/sass_stdlib.xml b/.idea/libraries/sass_stdlib.xml
deleted file mode 100644
index 8962a7d..0000000
--- a/.idea/libraries/sass_stdlib.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index ffedcd3..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
- jar:file:\D:\Program Files\JetBrains\WebStorm 5.0.4\lib\webide.jar!\resources\html5-schema\html5.rnc
-
-
-
-
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index a2d47c1..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/.idea/nodejs.iml b/.idea/nodejs.iml
deleted file mode 100644
index 3b09ca3..0000000
--- a/.idea/nodejs.iml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml
deleted file mode 100644
index 0d5175c..0000000
--- a/.idea/scopes/scope_settings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index ab55cf1..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/NodeSample/.gitignore b/NodeSample/.gitignore
new file mode 100644
index 0000000..3a58336
--- /dev/null
+++ b/NodeSample/.gitignore
@@ -0,0 +1,4 @@
+*.log
+.project
+node_modules/*
+node_modules/
\ No newline at end of file
diff --git a/NodeSample/controllers/article.js b/NodeSample/controllers/article.js
index a88f61a..99ee9f1 100644
--- a/NodeSample/controllers/article.js
+++ b/NodeSample/controllers/article.js
@@ -1,23 +1,21 @@
"use strict";
-var config = require('../config');
var fs = require('fs');
-var util = require('util');
var articleDBModel = require('../models/article.js');
-var log = require('../utils/logger.js');
-var logger =new log.init("filelog.txt");
-exports.setup = function(callback) { callback(null); }
-var article =new articleDBModel.Schema("articleType").model;
-var articleDetail =articleDBModel.Schema("articleDetail").model;
+exports.setup = function (callback) {
+ callback(null);
+}
+var article = new articleDBModel.Schema("articleType").model;
+var articleDetail = articleDBModel.Schema("articleDetail").model;
exports.saveArticleType = function (req, res, next) {
- exports.findUpload(req,res);
+ exports.findUpload(req, res);
var articleEntity = new article();
articleEntity.articleType = req.body.txtArticleType;
- if(req.body.id){
- articleEntity._id=req.body.id;
+ if (req.body.id) {
+ articleEntity._id = req.body.id;
}
- articleEntity.describe = req.body.txtDescribe;
- articleEntity.logoSrc ="logo.png";
+ articleEntity.describe = req.body.txtDescribe;
+ articleEntity.logoSrc = "logo.png";
articleEntity.save(function (err, row) {
if (err) {
return next(err);
@@ -25,31 +23,31 @@ exports.saveArticleType = function (req, res, next) {
res.redirect('/article/listContext');
});
};
-exports.findUpload=function(req,res){
+exports.findUpload = function (req, res) {
var tmp_path = req.files.articleLogo.path;
- console.log("temp_path->"+tmp_path);
+ console.log("temp_path->" + tmp_path);
// 指定文件上传后的目录 - 示例为"images"目录。
var target_path = './public/upload/imgages/' + req.files.articleLogo.name;
console.log(target_path);
var readStream = fs.createReadStream(tmp_path)
var writeStream = fs.createWriteStream(target_path);
readStream.pipe(writeStream);
- readStream.on('end',function() {
+ readStream.on('end', function () {
fs.unlinkSync(tmp_path);
- // res.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes' + "target_path" + target_path);
+ // res.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes' + "target_path" + target_path);
});
}
exports.saveArticleDetail = function (req, res, next) {
- var articleDetailEntity = new articleDetail();
+ var articleDetailEntity = new articleDetail();
articleDetailEntity.title = req.body.txtTitle || '';
- if(req.body.id){
- // articleDetailEntity._id=req.body.id;
+ if (req.body.id) {
+ // articleDetailEntity._id=req.body.id;
}
- articleDetailEntity.summary=req.body.txtSummary;
- articleDetailEntity.content=req.body.txtContent;
- articleDetailEntity.refArticleId=req.body.txtType;
+ articleDetailEntity.summary = req.body.txtSummary;
+ articleDetailEntity.content = req.body.txtContent;
+ articleDetailEntity.refArticleId = req.body.txtType;
articleDetailEntity.save(function (err, row) {
if (err) {
return next(err);
@@ -58,127 +56,159 @@ exports.saveArticleDetail = function (req, res, next) {
res.redirect('/article/listContext');
});
};
-exports.index = function(req,res,next){
- db.allContent(function (err, indexContent) {
- res.render('index.html', {indexContent: indexContent});
+exports.index = function (req, res, next) {
+ db.allContent(function (err, indexContent) {
+ res.render('index.html', {
+ indexContent: indexContent
+ });
});
-
+
};
-exports.articleTypeAll=function(req,res,next){
+exports.articleTypeAll = function (req, res, next) {
//var articleEntity = new article();
- article.find({},function (err,result){
+ article.find({}, function (err, result) {
console.log(result);
res.send(result);
});
}
-exports.articleTypeAll=function(req,res,next){
+exports.articleTypeAll = function (req, res, next) {
//var articleEntity = new article();
- article.find({},function (err,result){
+ article.find({}, function (err, result) {
console.log(result);
res.send(result);
});
}
-exports.articleItem=function(req,res,next){
+exports.articleItem = function (req, res, next) {
//var articleEntity = new article();
- article.find({},function (err,result){
- res.render('./article/article.html',{articleItem:result});
+ article.find({}, function (err, result) {
+ res.render('./article/article.html', {
+ articleItem: result
+ });
});
}
-exports.search = function(req,res,next){
- var searchKey = req.body.searchKey;
- if(searchKey){
- res.render('./article/search.html',{articleItem:""});
- }else{
- res.render('./article/search.html',{articleItem:""});
+exports.search = function (req, res, next) {
+ var searchKey = req.body.searchKey;
+ if (searchKey) {
+ res.render('./article/search.html', {
+ articleItem: ""
+ });
+ } else {
+ res.render('./article/search.html', {
+ articleItem: ""
+ });
}
}
-exports.initManager=function (req,res,next){
- var articleDetailEntity = new articleDetail();
- if(req.params.articleId){
- articleDetail.find({_id:req.params.articleId}, function (err, row) {
+exports.initManager = function (req, res, next) {
+ var articleDetailEntity = new articleDetail();
+ if (req.params.articleId) {
+ articleDetail.find({
+ _id: req.params.articleId
+ }, function (err, row) {
if (err) {
return next(err);
}
if (!row) {
return next();
}
- res.render('./article/articleManager.html',{article:row});
+ res.render('./article/articleManager.html', {
+ article: row
+ });
+ });
+ } else {
+ res.render('./article/articleManager.html', {
+ article: articleDetailEntity
});
- }else{
- res.render('./article/articleManager.html',{article:articleDetailEntity});
}
};
-exports.articleDetail=function (req,res,next){
- if(req.params.articleId){
- articleDetail.find({_id:req.params.articleId}, function (err, row) {
+exports.articleDetail = function (req, res, next) {
+ if (req.params.articleId) {
+ articleDetail.find({
+ _id: req.params.articleId
+ }, function (err, row) {
if (err) {
return next(err);
}
if (!row) {
return next();
}
- res.render('./article/articleDetail.html',{article:row});
+ res.render('./article/articleDetail.html', {
+ article: row
+ });
+ });
+ } else {
+ res.render('./article/articleDetail.html', {
+ article: articleDetailEntity
});
- }else{
- res.render('./article/articleDetail.html',{article:articleDetailEntity});
}
};
-exports.initDetailManager=function (req,res,next){
- if(req.params.id){
- db.find({_id:req.params.articleId}, function (err, row) {
- if (err) {
- return next(err);
- }
- if (!row) {
- return next();
- }
- res.render('./article/articleManager.html',{article:row});
- });
- }else{
-
- res.render('./article/articleManager.html',{article:articleDetailEntity});
- }
+exports.initDetailManager = function (req, res, next) {
+ if (req.params.id) {
+ db.find({
+ _id: req.params.articleId
+ }, function (err, row) {
+ if (err) {
+ return next(err);
+ }
+ if (!row) {
+ return next();
+ }
+ res.render('./article/articleManager.html', {
+ article: row
+ });
+ });
+ } else {
+
+ res.render('./article/articleManager.html', {
+ article: articleDetailEntity
+ });
+ }
};
//代码片段
-exports.listContextPage = function(req, res) {
- var search={};
- var page={limit:5,num:1};
- //查看哪页
- if(req.query.p){
- page['num']=req.query.p<1?1:req.query.p;
- }
- var model = {
- search:search,
- columns:'name alias director publish images.coverSmall create_date type deploy',
- page:page
- };
- exports.findPagination(model,function(err, pageCount, articleList){
- console.log("pageCount"+pageCount+" articleList"+articleList.length);
- page['pageCount']=pageCount;
- page['size']=articleList.length;
- page['numberOf']=pageCount>5?5:pageCount;
- res.render('./article/articleList.html', {articleList: articleList,page:page});
- });
+exports.listContextPage = function (req, res) {
+ var search = {};
+ var page = {
+ limit: 5,
+ num: 1
+ };
+ //查看哪页
+ if (req.query.p) {
+ page['num'] = req.query.p < 1 ? 1 : req.query.p;
+ }
+ var model = {
+ search: search,
+ columns: 'name alias director publish images.coverSmall create_date type deploy',
+ page: page
+ };
+ exports.findPagination(model, function (err, pageCount, articleList) {
+ console.log("pageCount" + pageCount + " articleList" + articleList.length);
+ page['pageCount'] = pageCount;
+ page['size'] = articleList.length;
+ page['numberOf'] = pageCount > 5 ? 5 : pageCount;
+ res.render('./article/articleList.html', {
+ articleList: articleList,
+ page: page
+ });
+ });
}
-exports.findPagination = function(obj,callback) {
- var q=obj.search||{}
- var col=obj.columns;
+exports.findPagination = function (obj, callback) {
+ var q = obj.search || {}
+ var col = obj.columns;
- var pageNumber=obj.page.num||1;
- var resultsPerPage=obj.page.limit||10;
+ var pageNumber = obj.page.num || 1;
+ var resultsPerPage = obj.page.limit || 10;
var skipFrom = (pageNumber * resultsPerPage) - resultsPerPage;
var query = articleDetail.find({}).sort('-create_date').skip(skipFrom).limit(resultsPerPage);
- query.exec(function(error, results) {
+ query.exec(function (error, results) {
if (error) {
callback(error, null, null);
} else {
- articleDetail.count(q, function(error, count) {
+ articleDetail.count(q, function (error, count) {
if (error) {
callback(error, null, null);
} else {
@@ -192,14 +222,14 @@ exports.findPagination = function(obj,callback) {
exports.deleteContectById = function (req, res, next) {
var id = req.params.id;
- exports.find({_id:id}, function(err, doc) {
+ exports.find({
+ _id: id
+ }, function (err, doc) {
if (err)
callback(err);
else {
doc.remove();
- res.send("删除成功!")
+ res.send("删除成功!")
}
});
-};
-
-
+};
\ No newline at end of file
diff --git a/NodeSample/controllers/index.js b/NodeSample/controllers/index.js
index 7cba924..0caca1c 100644
--- a/NodeSample/controllers/index.js
+++ b/NodeSample/controllers/index.js
@@ -1,8 +1,7 @@
"use strict";
-var config = require('../config');
-exports.index = function(req,res,next){
+exports.index = function (req, res, next) {
res.render('index.html');
-
+
}
\ No newline at end of file
diff --git a/NodeSample/controllers/todo.js b/NodeSample/controllers/todo.js
index a10fb01..b7c7f80 100644
--- a/NodeSample/controllers/todo.js
+++ b/NodeSample/controllers/todo.js
@@ -1,20 +1,16 @@
-var config = require('../config');
-var fs = require('fs');
-var util = require('util');
var todoDBModel = require('../models/todo.js');
var log = require('../utils/logger.js');
-var logger =new log.init("filelog.txt");
-var todo =todoDBModel.Schema("todoManager").model;
+var todo = todoDBModel.Schema("todoManager").model;
exports.saveTodo = function (req, res, next) {
var todoEntity = new todo();
todoEntity.taskType = req.body.txtArticleType;
- if(req.body.id){
- todoEntity._id=req.body.id;
+ if (req.body.id) {
+ todoEntity._id = req.body.id;
}
- todoEntity.status = req.body.txtDescribe;
- todoEntity.title ="logo.png";
+ todoEntity.status = req.body.txtDescribe;
+ todoEntity.title = "logo.png";
todoEntity.project = "";
- todoEntity.startDate= new Date();
+ todoEntity.startDate = new Date();
todoEntity.endDate = new Date();
todoEntity.priority = 0;
todoEntity.save(function (err, row) {
@@ -25,64 +21,76 @@ exports.saveTodo = function (req, res, next) {
});
};
-exports.todoAll=function(req,res,next){
+exports.todoAll = function (req, res, next) {
- todo.find({},function (err,result){
+ todo.find({}, function (err, result) {
console.log(result);
res.send(result);
});
}
-exports.initManager=function (req,res,next){
+exports.initManager = function (req, res, next) {
// var articleDetailEntity = new articleDetail();
- if(req.params.articleId){
- todo.find({_id:req.params.todoId}, function (err, row) {
+ if (req.params.articleId) {
+ todo.find({
+ _id: req.params.todoId
+ }, function (err, row) {
if (err) {
return next(err);
}
if (!row) {
return next();
}
- res.render('./article/articleManager.html',{article:row});
+ res.render('./article/articleManager.html', {
+ article: row
+ });
+ });
+ } else {
+ res.render('./article/articleManager.html', {
+ article: articleDetailEntity
});
- }else{
- res.render('./article/articleManager.html',{article:articleDetailEntity});
}
};
//代码片段
-exports.listContextPage = function(req, res) {
- var search={};
- var page={limit:5,num:1};
+exports.listContextPage = function (req, res) {
+ var search = {};
+ var page = {
+ limit: 5,
+ num: 1
+ };
//查看哪页
- if(req.query.p){
- page['num']=req.query.p<1?1:req.query.p;
+ if (req.query.p) {
+ page['num'] = req.query.p < 1 ? 1 : req.query.p;
}
var model = {
- search:search,
- columns:'name alias director publish images.coverSmall create_date type deploy',
- page:page
+ search: search,
+ columns: 'name alias director publish images.coverSmall create_date type deploy',
+ page: page
};
- exports.findPagination(model,function(err, pageCount, articleList){
- page['pageCount']=pageCount;
- page['size']=articleList.length;
- page['numberOf']=pageCount>5?5:pageCount;
- res.render('./article/articleList.html', {todoList: articleList,page:page});
+ exports.findPagination(model, function (err, pageCount, articleList) {
+ page['pageCount'] = pageCount;
+ page['size'] = articleList.length;
+ page['numberOf'] = pageCount > 5 ? 5 : pageCount;
+ res.render('./article/articleList.html', {
+ todoList: articleList,
+ page: page
+ });
});
}
-exports.findPagination = function(obj,callback) {
- var q=obj.search||{}
- var col=obj.columns;
- var pageNumber=obj.page.num||1;
- var resultsPerPage=obj.page.limit||10;
+exports.findPagination = function (obj, callback) {
+ var q = obj.search || {}
+ var col = obj.columns;
+ var pageNumber = obj.page.num || 1;
+ var resultsPerPage = obj.page.limit || 10;
var skipFrom = (pageNumber * resultsPerPage) - resultsPerPage;
var query = todo.find({}).sort('-create_date').skip(skipFrom).limit(resultsPerPage);
- query.exec(function(error, results) {
+ query.exec(function (error, results) {
if (error) {
callback(error, null, null);
} else {
- todo.count(q, function(error, count) {
+ todo.count(q, function (error, count) {
if (error) {
callback(error, null, null);
} else {
@@ -96,7 +104,9 @@ exports.findPagination = function(obj,callback) {
exports.deleteTodoById = function (req, res, next) {
var id = req.params.id;
- exports.find({_id:id}, function(err, doc) {
+ exports.find({
+ _id: id
+ }, function (err, doc) {
if (err)
callback(err);
else {
@@ -104,6 +114,4 @@ exports.deleteTodoById = function (req, res, next) {
res.send("删除成功!")
}
});
-};
-
-
+};
\ No newline at end of file
diff --git a/NodeSample/controllers/user.js b/NodeSample/controllers/user.js
index 07ab039..a8ba861 100644
--- a/NodeSample/controllers/user.js
+++ b/NodeSample/controllers/user.js
@@ -1,46 +1,55 @@
"use strict";
-var config = require('../config');
var userDBModel = require('../models/user.js');
var crypt = require('../utils/crypt.js');
-var user =new userDBModel.Schema("user").model;
+var user = new userDBModel.Schema("user").model;
exports.login = function (req, res, next) {
- res.render('login.html',{message:""});
+ res.render('login.html', {
+ message: ""
+ });
};
exports.onLogin = function (req, res, next) {
- var mdPassword=crypt.md5(req.body.password);
- var queryObj = {userName:req.body.userName,password:mdPassword};
- user.findOne(queryObj,function(err,userInfo){
- if(err){
-
- res.render('./login.html',{message:"登陆失败!"});
- }else{
- if(userInfo){
- res.redirect("/index")
- }else{
- res.render('./login.html',{message:"用户名和密码错误!"});
- }
- }
- })
+ var mdPassword = crypt.md5(req.body.password);
+ var queryObj = {
+ userName: req.body.userName,
+ password: mdPassword
+ };
+ user.findOne(queryObj, function (err, userInfo) {
+ if (err) {
+
+ res.render('./login.html', {
+ message: "登陆失败!"
+ });
+ } else {
+ if (userInfo) {
+ res.redirect("/index")
+ } else {
+ res.render('./login.html', {
+ message: "用户名和密码错误!"
+ });
+ }
+ }
+ })
};
- exports.addUser = function (){
- var userEntity = new user();
- userEntity.userName=req.body.userName;
- userEntity.password=req.body.password;
- userEntity.save(function (err,userInfo){
+exports.addUser = function () {
+ var userEntity = new user();
+ userEntity.userName = req.body.userName;
+ userEntity.password = req.body.password;
+ userEntity.save(function (err, userInfo) {
- })
- };
+ })
+};
-exports.userList=function(req, res, next){
- user.find({},function(err,userList){
- res.render('./user/users.html',{userList:userList});
+exports.userList = function (req, res, next) {
+ user.find({}, function (err, userList) {
+ res.render('./user/users.html', {
+ userList: userList
+ });
});
};
-exports.userManager = function (req,res,next){
-
-};
+exports.userManager = function (req, res, next) {
+};
\ No newline at end of file
diff --git a/NodeSample/models/article.js b/NodeSample/models/article.js
index 7280f81..a4a61d5 100644
--- a/NodeSample/models/article.js
+++ b/NodeSample/models/article.js
@@ -1,24 +1,31 @@
-var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//定义article type实体对象模型
var articleTypeScheme = new Schema({
- articleType:String
- ,describe:String
- ,logoSrc:String
+ articleType: String,
+ describe: String,
+ logoSrc: String
//,create_date: { type: Date, default: Date.now }
});
//定义article details对象模型
var articleDetailScheme = new Schema({
- title:String
- ,summary:String
- ,content:String
- ,create_date: { type: Date, default: Date.now }
- ,refArticleId:{ type: Schema.Types.ObjectId, ref: 'articleType' }
+ title: String,
+ summary: String,
+ content: String,
+ create_date: {
+ type: Date,
+ default: Date.now
+ },
+ refArticleId: {
+ type: Schema.Types.ObjectId,
+ ref: 'articleType'
+ }
});
mongoose.model('articleType', articleTypeScheme);
mongoose.model('articleDetail', articleDetailScheme);
-module.exports.Schema =function (modelName){
- return{model:mongoose.model(modelName)};
-}
+module.exports.Schema = function (modelName) {
+ return {
+ model: mongoose.model(modelName)
+ };
+}
\ No newline at end of file
diff --git a/NodeSample/models/todo.js b/NodeSample/models/todo.js
index 7a4f08c..577fa98 100644
--- a/NodeSample/models/todo.js
+++ b/NodeSample/models/todo.js
@@ -5,21 +5,31 @@
* Time: 下午3:00
* To change this template use File | Settings | File Templates.
*/
-var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//定义article type实体对象模型
var todoTypeScheme = new Schema({
- taskType:String,
- status:String,
- title:String,
- project:String,
- startDate: { type: Date, default: Date.now },
- endDate: { type: Date, default: Date.now },
- priority:{type:int,default:0}
+ taskType: String,
+ status: String,
+ title: String,
+ project: String,
+ startDate: {
+ type: Date,
+ default: Date.now
+ },
+ endDate: {
+ type: Date,
+ default: Date.now
+ },
+ priority: {
+ type: int,
+ default: 0
+ }
});
mongoose.model('todoManager', todoTypeScheme);
-module.exports.Schema =function (modelName){
- return{model:mongoose.model(modelName)};
-}
+module.exports.Schema = function (modelName) {
+ return {
+ model: mongoose.model(modelName)
+ };
+}
\ No newline at end of file
diff --git a/NodeSample/models/user.js b/NodeSample/models/user.js
index 08c148a..8bbc391 100644
--- a/NodeSample/models/user.js
+++ b/NodeSample/models/user.js
@@ -1,14 +1,18 @@
-var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
- userName:String,
- password:String,
- email:String,
- create_date: { type: Date, default: Date.now }
+ userName: String,
+ password: String,
+ email: String,
+ create_date: {
+ type: Date,
+ default: Date.now
+ }
});
//访问todo对象模型
mongoose.model('user', userSchema);
-module.exports.Schema =function (modelName){
- return{model:mongoose.model(modelName)};
-}
+module.exports.Schema = function (modelName) {
+ return {
+ model: mongoose.model(modelName)
+ };
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index 7f7c579..4fe2920 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,24 @@
-###node.js
+## node.js
+
+本项目 2012 年 是基于 nodejs 0.8 版本开发的,无法运行,如果学习,请直接查看代码,谢谢
+
=======
-Node.js+express.js+mongoose+ejs+monogdb知识库管理系统
-> 框架用的MVC方式。
-> > 基于express.js 的MVC方式实现
+Node.js+express.js+mongoose+ejs+monogdb 知识库管理系统
+
+> 框架用的 MVC 方式。
+>
+> > 基于 express.js 的 MVC 方式实现
> 博客管理
+>
> > 文件博客分类管理
> > 博客搜索功能
> 文件管理
+>
> > 包括多文件异步带进度的上传方式
> > 图片高性能加载
> 用户管理
+>
> > 用户权限管理系统
-