a plugin for mongoose base user model for koa && express
MIT License
a base user plugin for mongoose
npm i -S mongoose-base-user-plugin
create a model like user.js
var mongoose = require('mongoose');
var base_user = require('.')
var MyUserSchema = new mongoose.Schema({
invite_code : String, // 邀请码
phone_number : Number, // 电话号码
address : String, // 地址
unionid : String,
nickname : String,// from weixin 昵称
sex : String,// from weixin 性别 0->女 1->男
language : String,// from weixin 语言
city : String,// from weixin 城市
province : String,// from weixin
country : String,// from weixin
headimgurl : String,// from weixin 头像路径
privilege : [], // from weixin
created_at : {
type: Date,
"default": Date.now
}
});
MyUserSchema.plugin(base_user);
// 定义Model
var UserModel = mongoose.model('MyUser', MyUserSchema);
// 暴露接口
module.exports = UserModel;
User.login('i5ting 2', '0123456', function (err, result) {
})
it depend on g++, so in .travis.yml
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
env:
- CXX=g++-4.8
Note: OS X users using Xcode 4.3.1 or above may need to run the following command in their terminal prior to installing if errors occur regarding xcodebuild: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
if you deploy on ubuntu, make sure that g++ is available.
提示,当发现bcrypt无法安装的时候
> [email protected] install ~/workspace/github/mongoose-base-user-plugin/node_modules/bcrypt
> node-gyp rebuild
gyp: ~/.node-gyp/4.4.5/common.gypi not found (cwd: ~/workspace/github/mongoose-base-user-plugin/node_modules/bcrypt) while reading includes of binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (~/.nvm/versions/node/v4.4.5/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:343:16)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 14.5.0
gyp ERR! command "~/.nvm/versions/node/v4.4.5/bin/node" "~/.nvm/versions/node/v4.4.5/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd ~/workspace/github/mongoose-base-user-plugin/node_modules/bcrypt
gyp ERR! node -v v4.4.5
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm ERR! Darwin 14.5.0
npm ERR! argv "~/.nvm/versions/node/v4.4.5/bin/node" "~/.nvm/versions/node/v4.4.5/bin/npm" "i"
npm ERR! node v4.4.5
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls bcrypt
npm ERR! There is likely additional logging output above.
解决方案
rm -rf ~/.node_gyp
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)i5ting
[email protected]
如有建议或意见,请在issue提问或邮件
this repo is released under the MIT License.