【发布时间】:2015-12-15 16:32:36
【问题描述】:
我的模型看起来像这样,但是当我尝试使用 verifyPassword 时,它显示为 TypeError: user.verifyPassword is not a function
const User = new mongoose.Schema({
name: {
type: String,
required: true
},
password: {
type: String,
required: true
},
avatar: String,
token: String,
role: String,
permissions: Array,
email: {
type: String,
unique: true,
required: true
},
joined: {
type: Number,
default: ( new Date() * 1 )
}
})
User.methods.verifyPassword = function (password) {
return bcrypt.compare(password, this.password)
}
我就是这样用的。
yield User.find({
email: this.request.body.email
}).exec()
.then( user => {
if ( user.verifyPassword(self.request.body.password) ) {
self.status = 200
self.body = {
token: user.token
}
} else {
self.status = 500
self.body = "Problem signing in."
}
}, error => {
self.status = 500
self.body = "Problem signing in."
})
【问题讨论】:
标签: node.js mongodb mongoose koa