candy
Advanced tools
Comparing version 0.0.3 to 0.0.4
34
app.js
@@ -15,3 +15,4 @@ // __ __ | ||
path = require('path'), | ||
MongoStore = require('connect-mongo')(express); | ||
MongoStore = require('connect-mongo')(express), | ||
self = this; | ||
@@ -38,10 +39,16 @@ var app = express(), | ||
app.use(express.methodOverride()); | ||
app.use(express.cookieParser('tesla')); | ||
app.use(express.cookieParser(params.database.name)); | ||
app.use(express.session({ | ||
secret: 'tesla', | ||
secret: params.database.name, | ||
store: new MongoStore({ | ||
db: 'tesla', | ||
db: params.database.name, | ||
collection: 'sessions' | ||
}) | ||
})); | ||
app.use(function(req,res,next){ | ||
if (!res.locals.App) { | ||
res.locals.App = self; | ||
} | ||
next(); | ||
}) | ||
app.use(app.router); | ||
@@ -59,3 +66,3 @@ app.use(require('less-middleware')({ | ||
// home | ||
app.get('/', index); | ||
app.get('/', sign.passport, index); | ||
@@ -67,3 +74,3 @@ // signin & signout | ||
// board | ||
app.get('/board/:id', board.read); | ||
app.get('/board/:id', sign.passport, board.read); | ||
app.post('/board/:id', board.update); | ||
@@ -75,3 +82,3 @@ app.post('/board/new', board.create); | ||
app.get('/thread/new', sign.check, thread.new); | ||
app.get('/thread/:id',thread.read); | ||
app.get('/thread/:id', sign.passport, thread.read); | ||
app.post('/thread/new', thread.create); | ||
@@ -82,14 +89,17 @@ app.post('/thread/remove', thread.remove); | ||
// user | ||
app.get('/user/:id', user.read); | ||
app.get('/user/:id', sign.passport , user.read); | ||
app.post('/user/new', user.create); | ||
app.post('/user/remove', user.remove); | ||
app.post('/user/sync', sign.check , user.sync); | ||
app.post('/user/sync', sign.check, user.sync); | ||
app.post('/user/:id', user.update); | ||
// mime | ||
app.get('/mime', user.mime); | ||
app.get('/mime', sign.passport, user.mime); | ||
// admin | ||
app.get('/admin', sign.checkAdmin , admin); | ||
app.get('/admin', sign.checkMaster, sign.checkAdmin, admin.page); | ||
// setting | ||
app.post('/setting', admin.update); | ||
this.app = app; | ||
@@ -146,3 +156,3 @@ this.params = params; | ||
} | ||
self.config(function(){ | ||
self.config(function() { | ||
http.createServer(self.app).listen(self.app.get('port')); | ||
@@ -149,0 +159,0 @@ }); |
var model = require('../model'), | ||
board = model.board; | ||
// list board | ||
exports.ls = function(cb){ | ||
board.find({}).exec(function(err,boards){ | ||
if (!err) { | ||
cb(boards) | ||
} else { | ||
cb('error'); | ||
} | ||
}); | ||
} | ||
exports.read = function(id,cb){ | ||
@@ -5,0 +16,0 @@ board.findById(id).populate('threads').populate('bz').exec(function(err,board){ |
var model = require('../model'), | ||
config = model.config; | ||
var wash = function(baby) { | ||
var baby = baby; | ||
if (baby.hasOwnProperty('_id')) { | ||
delete baby._id; | ||
} | ||
if (baby.hasOwnProperty('__v')) { | ||
delete baby.__v; | ||
} | ||
return baby | ||
} | ||
// 写入配置 | ||
@@ -16,2 +27,14 @@ exports.create = function(baby,cb){ | ||
// update | ||
exports.update = function(id,baby,cb) { | ||
var baby = wash(baby); | ||
config.findByIdAndUpdate(id,baby,function(err,result){ | ||
if (!err) { | ||
cb(result); | ||
} else { | ||
console.log(err); | ||
} | ||
}) | ||
} | ||
// 读取配置 | ||
@@ -18,0 +41,0 @@ exports.readById = function(cb) { |
var model = require('../model'), | ||
thread = model.thread; | ||
// list thread | ||
exports.ls = function(cb){ | ||
thread.find({}).exec(function(err,threads){ | ||
if (!err) { | ||
cb(threads) | ||
} else { | ||
cb('error'); | ||
} | ||
}); | ||
} | ||
exports.read = function(id,cb){ | ||
@@ -5,0 +16,0 @@ thread.findById(id).populate('lz').populate('board').exec(function(err,thread){ |
@@ -5,3 +5,36 @@ var model = require('../model'), | ||
// list users | ||
exports.ls = function(cb){ | ||
user.find({}).exec(function(err,us){ | ||
if (!err) { | ||
cb(us) | ||
} else { | ||
cb('error'); | ||
} | ||
}); | ||
} | ||
// count users | ||
exports.count = function(cb){ | ||
user.count({},function(err,count){ | ||
if (!err) { | ||
cb(count) | ||
} else { | ||
cb('error'); | ||
} | ||
}); | ||
} | ||
// 读取一个用户 | ||
exports.query = function(id,cb){ | ||
user.findById(id).exec(function(err,user){ | ||
if (!err) { | ||
cb(user) | ||
} else { | ||
cb('error') | ||
} | ||
}); | ||
} | ||
// 读取一个用户 | ||
exports.read = function(id,cb){ | ||
@@ -8,0 +41,0 @@ user.findById(id).populate('thread').exec(function(err,user){ |
@@ -6,3 +6,3 @@ /** | ||
var mongoose = require('mongoose'), | ||
db = mongoose.createConnection('localhost', 'tesla'), | ||
db = mongoose.createConnection('localhost', 'candy'), | ||
Schema = mongoose.Schema; | ||
@@ -14,2 +14,3 @@ | ||
desc: String, | ||
url: String, | ||
duoshuo: { | ||
@@ -16,0 +17,0 @@ short_name: String, |
{ | ||
"name": "candy", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "a micro bbs system based on duoshuo.com apis", | ||
@@ -18,3 +18,4 @@ "main": "app.js", | ||
"forum", | ||
"duoshuo" | ||
"duoshuo", | ||
"social" | ||
], | ||
@@ -27,3 +28,2 @@ "author": "turing", | ||
"dependencies": { | ||
"beer": "*", | ||
"duoshuo":"*", | ||
@@ -34,3 +34,5 @@ "express": "3.3.1", | ||
"connect-mongo":"*", | ||
"mongoose": "*" | ||
"mongoose": "*", | ||
"async": "*", | ||
"ifile": "*" | ||
}, | ||
@@ -37,0 +39,0 @@ "devDependencies": { |
// 定义这个数据仓库 | ||
var store = angular.module('store', ['ngResource']).factory('Store', function($resource) { | ||
return { | ||
// define user api | ||
user: $resource('/user/:id', {id:'@uid'}), | ||
// define article api | ||
article : $resource('/article/:id', {id:'@aid'}), | ||
// define jsonp api | ||
remote : $resource('/remoteData/:id', {id:'@rid'},{ | ||
jsonp :{ | ||
method:'JSONP', | ||
params:{ | ||
yourKey: 'yourValue' | ||
} | ||
} | ||
}) | ||
user: $resource('/user/:action', {action:'@action'}), | ||
board: $resource('/board/:action', {action:'@action'}), | ||
thread : $resource('/thread/:action', {action:'@action'}), | ||
setting : $resource('/setting', {}) | ||
} | ||
}) |
@@ -6,2 +6,4 @@ ![logo](http://ww1.sinaimg.cn/large/61ff0de3gw1e7d9luh49bj201201bdfm.jpg) Candy ![](https://badge.fury.io/js/candy.png) | ||
![demo](http://ww1.sinaimg.cn/large/61ff0de3gw1e7edq7tkiuj20vc0m0786.jpg) | ||
### How to install | ||
@@ -15,12 +17,33 @@ | ||
#### Start a candy server by defalut | ||
I've prepare a script for you: | ||
```` | ||
$ git clone https://github.com/turingou/candy.git | ||
$ cd candy | ||
$ vi server.js // edit configs | ||
$ node server.js | ||
```` | ||
or by NPM | ||
```` | ||
$ npm install candy | ||
$ cd node_modules/candy | ||
$ vi server.js // edit configs | ||
$ node server.js | ||
```` | ||
#### Start a candy server by `require` | ||
````javascript | ||
var candy = require('candy').server; | ||
var Candy = require('candy'); | ||
var myCandy = new candy.server({ | ||
name: 'My candy BBS', // 站点名称 | ||
url: 'http://abc.com', // 站点url | ||
desc: 'some desc', // 站点描述 | ||
var myCandy = new Candy.server({ | ||
name: 'My candy BBS', // site name | ||
url: 'http://abc.com', // site URL | ||
desc: 'some desc', // site description | ||
duoshuo: { | ||
short_name: 'xxx', // 多说 short_name | ||
secret: 'xxx' // 多说 secret | ||
short_name: 'xxx', // your duoshuo.com [short_name] | ||
secret: 'xxx' // your duoshuo.com [secret] | ||
} | ||
@@ -31,12 +54,34 @@ }); | ||
```` | ||
then save it to `candy.js`. | ||
```` | ||
$ node candy.js // or forever start candy.js | ||
```` | ||
#### Make your custom candy | ||
- 1. find `/public` folder and change `logo.png` to yours | ||
- 2. visit `/admin` panel to edit configs (site name , desc , etc.) | ||
- add boards or edit defalut borard desc. | ||
- write a thread and try to post it | ||
- explore and enjoy ~ | ||
### Pull Request Welcome ! | ||
- fork this repo | ||
- feel free to add your feature or emoticons | ||
- feel free to add your feature | ||
- make sure your feature are fully tested! | ||
- send me a PR, and enjoy ! | ||
### Candy demo site | ||
### Candy demos | ||
- [Teslaer: tesla电动车中国爱好者社区](http://teslaer.com) | ||
- [Teslaer: tesla电动车中国爱好者社区](http://teslaer.com) (now building...) | ||
### Candy features | ||
#### Mobile first | ||
![](http://ww3.sinaimg.cn/large/61ff0de3gw1e7edph6gnzj20ea0m0mz8.jpg) | ||
#### Easy to install and config | ||
#### Comments on cloud |
@@ -1,4 +0,21 @@ | ||
// index page | ||
module.exports = function(req, res){ | ||
res.render('admin/index'); | ||
// admin panel | ||
var admin = require('../ctrlers/admin'); | ||
exports.page = function(req, res) { | ||
admin.read(function(info){ | ||
res.render('admin/index',info); | ||
}) | ||
}; | ||
exports.update = function(req, res) { | ||
if (req.body.setting) { | ||
admin.update(req.body.setting,function(site){ | ||
res.locals.App.app.locals.site = site; | ||
res.json(site) | ||
}); | ||
} else { | ||
res.json({ | ||
stat: 'fail' | ||
}) | ||
} | ||
}; |
@@ -5,3 +5,6 @@ var board = require('../ctrlers/board'); | ||
board.read(req.params.id,function(b){ | ||
res.render('board',b) | ||
res.render('board',{ | ||
user: req.session.user, | ||
board: b | ||
}) | ||
}); | ||
@@ -8,0 +11,0 @@ } |
// index page | ||
module.exports = function(req, res){ | ||
res.render('index',{ | ||
user: req.session.user, | ||
boards: [{ | ||
@@ -6,0 +5,0 @@ url: 'demo', |
@@ -5,2 +5,21 @@ // sign | ||
var passport = function(req,res,next,cb) { | ||
if (req.session.user) { | ||
res.locals.user = req.session.user | ||
next() | ||
} else { | ||
cb(); | ||
} | ||
} | ||
var checkMaster = function(cb) { | ||
user.count(function(count){ | ||
if (count == 1) { | ||
cb(true) | ||
} else { | ||
cb(false); | ||
} | ||
}) | ||
} | ||
var createUser = function(result,cb) { | ||
@@ -31,7 +50,7 @@ user.create({ | ||
req.session.user = u; | ||
res.redirect('/'); | ||
res.redirect('back'); | ||
} else { | ||
createUser(result,function(baby){ | ||
req.session.user = baby; | ||
res.redirect('/'); | ||
res.redirect('back'); | ||
}); | ||
@@ -56,4 +75,36 @@ } | ||
exports.check = function(req,res,next) { | ||
passport(req,res,next,function(){ | ||
res.redirect('/'); | ||
}); | ||
} | ||
// set passport | ||
exports.passport = function(req,res,next) { | ||
passport(req,res,next,function(){ | ||
next(); | ||
}); | ||
} | ||
// check creater | ||
exports.checkMaster = function(req,res,next) { | ||
if (req.session.user) { | ||
next() | ||
checkMaster(function(stat){ | ||
if (stat) { | ||
user.query(req.session.user._id,function(u){ | ||
if (u && u != 'error') { | ||
u.type = 'admin'; | ||
u.save(function(err){ | ||
if (!err) { | ||
res.locals.user = u; | ||
next(); | ||
} else { | ||
console.log(err); | ||
} | ||
}) | ||
} | ||
}) | ||
} else { | ||
next(); | ||
} | ||
}) | ||
} else { | ||
@@ -66,4 +117,4 @@ res.redirect('/'); | ||
exports.checkAdmin = function(req,res,next) { | ||
if (req.session.user && req.session.user.type == 'admin') { | ||
next() | ||
if (req.session.user && (req.session.user.type == 'admin' || res.locals.user && res.locals.user.type == 'admin')) { | ||
next(); | ||
} else { | ||
@@ -70,0 +121,0 @@ res.redirect('/'); |
@@ -9,3 +9,5 @@ var thread = require('../ctrlers/thread'); | ||
thread.read(req.params.id,function(b){ | ||
res.render('thread/index',b) | ||
res.render('thread/index',{ | ||
thread: b | ||
}) | ||
}); | ||
@@ -12,0 +14,0 @@ } |
@@ -37,5 +37,3 @@ var user = require('../ctrlers/user'); | ||
exports.mime = function(req, res) { | ||
res.render('mime',{ | ||
user: req.session.user | ||
}) | ||
res.render('mime') | ||
} | ||
@@ -42,0 +40,0 @@ |
var Server = require('./app').server; | ||
new Server().run(); | ||
new Server({ | ||
name: 'Candy', // 站点名称 | ||
url: 'http://candy.com', // 站点url | ||
desc: 'some desc', // 站点描述 | ||
database: { | ||
name: 'candy' | ||
}, | ||
duoshuo: { | ||
short_name: 'candydemo', // 多说 short_name | ||
secret: '055834753bf452f248602e26221a8345' // 多说 secret | ||
} | ||
}).run(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
1068064
54
1650
84
8
8
+ Addedasync@*
+ Addedifile@*
+ Addedasync@3.2.5(transitive)
+ Addedifile@0.3.9(transitive)
+ Addedmime@1.2.6(transitive)
- Removedbeer@*
- Removedbeer@0.0.8(transitive)
- Removedunderscore@1.13.6(transitive)