Bookshelf里面的JS函数extend()
我正在使用http://bookshelfjs.org/
我在里面添加了一个函数
var User = Bookshelf.Model.extend({ ... // verify the password verifyPassword: function (password, hash, done) { // Load hash from your password DB. bcrypt.compare(password, hash.replace('$2y$', '$2a$'), function(err, result) { return done(err, result); }); } ... module.exports = User;
从我的用户控制器,我称之为:
var User = require('../models/user'); User.verifyPassword(req.body.password, user.password, function (err, result) {
但我没有得到no method 'verifyPassword
。
您需要在控制器中创build一个用户实例
var User = require('../models/user'); this.user = new User();
如果你想让你的用户模块总是返回一个实例,那么修改它就像这样。
var User = Bookshelf.Model.extend({ ... } ... module.exports = function(options){ return new User(options) };