at /var/www/html/chatnode/routes/login.js:24:26
at /var/www/html/chatnode/node_modules/async/dist/async.js:486:20
at nextTask (/var/www/html/chatnode/node_modules/async/dist/async.js:5008:33)
at /var/www/html/chatnode/node_modules/async/dist/async.js:5015:17
at /var/www/html/chatnode/node_modules/async/dist/async.js:339:31
at /var/www/html/chatnode/node_modules/async/dist/async.js:847:20
at /var/www/html/chatnode/models/user.js:53:11
at nextTask (/var/www/html/chatnode/node_modules/async/dist/async.js:5021:18)
at /var/www/html/chatnode/node_modules/async/dist/async.js:5015:17
at /var/www/html/chatnode/node_modules/async/dist/async.js:339:31
at /var/www/html/chatnode/node_modules/async/dist/async.js:847:20
at Query.<anonymous> (/var/www/html/chatnode/node_modules/mongoose/lib/model.js:3327:16)
at /var/www/html/chatnode/node_modules/kareem/index.js:259:21
at /var/www/html/chatnode/node_modules/kareem/index.js:127:16
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
вот routes/login.js
var User = require('models/user').User;
var HttpError = require('error').HttpError;
var AuthError = require('models/user').AuthError;
var async = require('async');
exports.get = function(req, res) {
res.render('login');
};
exports.post = function(req, res, next) {
var username = req.body.username;
var password = req.body.password;
User.authorize(username, password, function(err, user) {
if (err) {
if (err instanceof AuthError) {
return next(new HttpError(403, err.message));
} else {
return next(err);
}
}
req.session.user = User._id;
res.send({});
});
};
ругается на эту строку
req.session.user = User._id;
и на этот участок кода в models/user
schema.statics.authorize = function (username, password, callback) {
var User = this;
async.waterfall([
function (callback) {
User.findOne({username:username},callback);
},
function (user,callback) {
if(user){
if(user.checkPassword(password)){
callback(null, user);
}else{
callback(new AuthError("Пароль неверен"));
}
}else{
var user = new User({username:username,password:password})
user.save(function (err) {
if(err)return callback(err);
callback(null, user);
})
}
}
],callback);
};
exports.User = mongoose.model('User', schema);
ругается на эту часть
if(user){
if(user.checkPassword(password)){
callback(null, user);
}else{
callback(new AuthError("Пароль неверен"));
}
сразу оговорюсь я учусь по этому
скринкасту