节点& MongoDB - TypeError:无法设置未定义的属性'userProfileModel'

时间:2017-03-03 09:28:01

标签: javascript node.js mongodb mongoose

尝试在Postman中进行登录测试时出现此错误。我已经进行了注册测试,所有输入字段都注册了200状态,并确保使用Robomongo发布所有条目。但是当我尝试使用userNamepassword进行登录时,我会收到以下TypeError:

(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 } }));
    }

});

};

非常感谢有关此问题的任何帮助。

1 个答案:

答案 0 :(得分:0)

看起来像你"我"变量没有帐户变量/参数。