Skip to content

Commit

Permalink
窗口增删改查 完成
Browse files Browse the repository at this point in the history
  • Loading branch information
leftjs committed Jan 20, 2016
1 parent c10e3b7 commit 902cad6
Show file tree
Hide file tree
Showing 36 changed files with 727 additions and 457 deletions.
38 changes: 36 additions & 2 deletions dist/bizs/commonBiz.js

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

85 changes: 0 additions & 85 deletions dist/bizs/shopBiz.js

This file was deleted.

19 changes: 5 additions & 14 deletions dist/bizs/userBiz.js

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

Empty file removed dist/database/shop.db
Empty file.
18 changes: 13 additions & 5 deletions dist/database/users.db
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjlDbzlURGcydnpoTGVPR1giLCJpYXQiOjE0NTMyMTcxMzd9.y22TwPtEd_CCZVTmbgavb-BeIgC1Zz7tz6OaX06ACjs","expiredTime":1453303537111,"is_admin":false,"is_shopper":true,"_id":"9Co9TDg2vzhLeOGX"}
{"name":"匿名","username":"shopper","password":"30f1f5b7ab09f3c95ce5c5c824622d1a","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IlJLMnZDMUo5SExVQno2Rm8iLCJpYXQiOjE0NTMyMTcxMzd9.vzjsLPRJBNI0YR1Na9SvxHP44HcX3QSl9JqsCAumZZY","expiredTime":1453303537120,"is_admin":false,"is_shopper":true,"_id":"RK2vC1J9HLUBz6Fo"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImVYSEF2SGc4SExLcEhOSWYiLCJpYXQiOjE0NTMyMTcxMzd9.70MZxT3Np1QNjdfD0ycJlgXbwfc2EMPopiMelJ6OdKo","expiredTime":1453303537097,"is_admin":true,"is_shopper":false,"_id":"eXHAvHg8HLKpHNIf"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImVYSEF2SGc4SExLcEhOSWYiLCJpYXQiOjE0NTMyMTgxMzJ9.yC2REiHfs18jhxt8OsIjr2K1cWf7ShWY_0g97mvhp6w","expiredTime":1453304532157,"is_admin":true,"is_shopper":false,"_id":"eXHAvHg8HLKpHNIf"}
{"name":"匿名","username":"shopper","password":"30f1f5b7ab09f3c95ce5c5c824622d1a","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IlJLMnZDMUo5SExVQno2Rm8iLCJpYXQiOjE0NTMyMTgxMzJ9.KyLRsXxoWsOu1wJoyivnuBUJtvDo-0OrRIAegzL64JM","expiredTime":1453304532167,"is_admin":false,"is_shopper":true,"_id":"RK2vC1J9HLUBz6Fo"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"","expiredTime":1453310980791,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"","expiredTime":1453310980803,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"","expiredTime":1453310980817,"is_admin":true,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InFUNmNEdjZjN0FLQlhRV0giLCJpYXQiOjE0NTMzMTA5ODB9.N_RQlNJU2f1Xq3wnYlkhVo2jlmRjAgfTyxDTlkGvr-U","expiredTime":1453397380852,"is_admin":true,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ik5iejJHbFo2MmJsN1piQk8iLCJpYXQiOjE0NTMzMTA5ODB9.JloeVjVbeCUGZ548ByUEP6RJSlZLG6F0pVjyOP4LJVY","expiredTime":1453397380872,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"张三","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ik5iejJHbFo2MmJsN1piQk8iLCJpYXQiOjE0NTMzMTA5ODB9.JloeVjVbeCUGZ548ByUEP6RJSlZLG6F0pVjyOP4LJVY","expiredTime":1453397380872,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ik5iejJHbFo2MmJsN1piQk8iLCJpYXQiOjE0NTMzMTA5ODB9.JloeVjVbeCUGZ548ByUEP6RJSlZLG6F0pVjyOP4LJVY","expiredTime":1453397380872,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InFUNmNEdjZjN0FLQlhRV0giLCJpYXQiOjE0NTMzMTA5ODB9.N_RQlNJU2f1Xq3wnYlkhVo2jlmRjAgfTyxDTlkGvr-U","expiredTime":1453397380852,"is_admin":false,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InFUNmNEdjZjN0FLQlhRV0giLCJpYXQiOjE0NTMzMTA5ODB9.N_RQlNJU2f1Xq3wnYlkhVo2jlmRjAgfTyxDTlkGvr-U","expiredTime":1453397380852,"is_admin":true,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":false,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
4 changes: 2 additions & 2 deletions dist/libs/app.js

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

4 changes: 2 additions & 2 deletions dist/libs/db.js

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

33 changes: 0 additions & 33 deletions dist/routes/shop.js

This file was deleted.

20 changes: 20 additions & 0 deletions myplayground.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

commonBiz = require './src/bizs/commonBiz'

_ = require 'underscore'

oldData = {
name: '匿名'
username:'1232324'
token: ''
}

newData = {
name: '匿名aasdf'
username: 12
token:'asdfasdf'
}


result = commonBiz.concatPostData(oldData,newData,{'name'})
console.log(result)
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
"mongoose": "^4.3.4",
"morgan": "~1.6.1",
"nedb": "^1.5.1",
"serve-favicon": "~2.3.0"
"serve-favicon": "~2.3.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"del": "^2.2.0",
"gulp": "^3.9.0",
"gulp-develop-server": "^0.5.0",
"gulp-mocha": "^2.2.0",
"gulp-notify": "^2.2.0",
"lodash": "^4.0.0",
"run-sequence": "^1.1.5",
"should": "^8.1.1",
"supertest": "^1.1.0"
Expand Down
25 changes: 24 additions & 1 deletion src/bizs/commonBiz.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
db = require('./../libs/db')

_ = require('underscore')


# 自定义错误
customError = (status,msg) ->
err = new Error()
err.status = status
err.message = msg
return err

authIsAdmin = (id,callback) ->
db.users.findOne({_id: id},(err,user) ->
return next(err) if err
if user.is_admin
callback(true)
else
callback(false)
)


# 验证并授权用户
authAndSetUserInfo = (req,res,next) ->
token = req.header('x-token')
if not token
Expand All @@ -22,7 +34,18 @@ authAndSetUserInfo = (req,res,next) ->

)

concatPostData = (oldData,newData,allow=undefined ) ->
postData = {}
keys = _.keys(oldData)
_.each(newData,(value,key,list) ->
if _.contains(keys,key) && (allow is undefined || _.contains(allow,key))
postData[key] = value
)
return postData

module.exports = {
authAndSetUserInfo: authAndSetUserInfo
customError: customError
authIsAdmin: authIsAdmin
concatPostData: concatPostData
}
Loading

0 comments on commit 902cad6

Please sign in to comment.