0
我在嘗試在郵遞員中執行登錄測試時遇到此錯誤。我已經做了註冊測試,所有的輸入字段都註冊了200狀態,並確保所有的輸入都使用Robomongo發佈。但是,當我嘗試做userName
和password
登錄,這是我得到以下類型錯誤:Node&MongoDB - TypeError:無法設置屬性'userProfileModel'undefined
(node:13962) DeprecationWarning: crypto.pbkdf2 without specifying a digest is deprecated. Please specify a digest
/Users/Wilo/Desktop/myway_stuff/myway_app/MyWay/server/controllers/account.js:63
me.account.userProfileModel = userProfileModel;
^
TypeError: Cannot set property 'userProfileModel' of undefined
at InternalFieldObject.ondone (/Users/Wilo/Desktop/myway_stuff/myway_app/MyWay/server/controllers/account.js:63:49)
這裏就是登錄功能是我account.js
控制器內執行的代碼片段:
的AccountController。 prototype.logon = function(userName,password,callback){
var me = this;
me.userModel.findOne({ userName: userName }, function (err, user) {
if (err) {
return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.DB_ERROR } }));
}
if (user && user.passwordSalt) {
me.hashPassword(password, user.passwordSalt, function (err, passwordHash) {
if (passwordHash == user.passwordHash) {
var userProfileModel = new me.UserProfile({
userName: user.userName,
email: user.email,
firstName: user.firstName,
lastName: user.lastName
});
//Save to HTTP account
me.account.userProfileModel = userProfileModel; // This is Line 63 in the stacktrace
me.account.id = me.uuid.v4();
//Save to persistent account
me.userAccount.userId = user._id;
me.userAccount.accountId = me.account.id;
me.userAccount.save(function (err, accountData, numberAffected) {
if (err) {
return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.DB_ERROR } }));
}
if (numberAffected === 1) {
// Return the user profile so the router sends it to the client app doing the logon.
return callback(err, new me.ApiResponse({
success: true, extras: {
userProfileModel: userProfileModel,
accountId: me.account.id
}
}));
} else {
return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.COULD_NOT_CREATE_ACCOUNT } }));
}
});
} else {
return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.INVALID_PWD } }));
}
});
} else {
return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.EMAIL_NOT_FOUND } }));
}
});
};
希望對此問題有任何幫助。