我用 Mongoose 定义了一个实例方法来验证代表(用户):
RepSchema.methods.authenticate = function(password){
return this.encryptPassword(password) === this.hashed_password;
};
在我的应用程序中,我找到了代表并调用了authenticate
它的方法:
var mongoose = require("mongoose");
var Rep = mongoose.model("Rep");
Rep.findOne({email: email}, function(err, rep){
if (rep.authenticate(req.body.session.password)){
req.session.rep_id = rep._id;
res.redirect('/calls', {});
}
});
但是我收到此错误:
TypeError: Object { email: 'meltzerj@wharton.upenn.edu',
password: XXXXXXXXX,
name: 'meltz',
_id: 4fbc6fcb2777fa0272000003,
created_at: Wed, 23 May 2012 05:04:11 GMT,
confirmed: false,
company_head: false } has no method 'authenticate'
我究竟做错了什么?