Intereting Posts


我想这样做,当用户注册我的网站,他们得到一封电子邮件,说他们需要validation他们的电子邮件使用该网站。 它目前发送带有令牌的电子邮件,但是当我去到确认链接时,它失败, status 404

路线'/confirmation/:token', users.confirmationPost); 


 var users = require('../controllers/users-controller'); 


 exports.confirmationPost = function (req, res, next) { req.assert('email', 'Email is not valid').isEmail(); req.assert('email', 'Email cannot be blank').notEmpty(); req.assert('token', 'Token cannot be blank').notEmpty(); req.sanitize('email').normalizeEmail({ remove_dots: false }); // Check for validation errors var errors = req.validationErrors(); if (errors) return res.status(400).send(errors); // Find a matching token Token.findOne({ token: req.body.token }, function (err, token) { if(err) throw err; if (!token) return res.status(400).send({ type: 'not-verified', msg: 'We were unable to find a valid token. Your token my have expired.' }); // If we found a token, find a matching user User.findOne({ _id: token._userId }, function (err, user) { if(err) throw err; if (!user) return res.status(400).send({ msg: 'We were unable to find a user for this token.' }); if (user.isVerified) return res.status(400).send({ type: 'already-verified', msg: 'This user has already been verified.' }); // Verify and save the user user.isVerified = true; (err) { if (err) { return res.status(500).send({ msg: err.message }); } res.status(200).send("The account has been verified. Please log in."); }); }); }); }; 


 passport.use('signup', new LocalStrategy({ usernameField: 'email', passReqToCallback : true }, function(req, email, password, done) { var findOrCreateUser = function(){ User.findOne({ email: }, function(err, existingUser) { if(err){ console.log(err); } if (existingUser) { req.flash('form', { email: }); return done(null, false, req.flash('error', 'An account with that email address already exists.')); } // edit this portion to accept other properties when creating a user. var user = new User({ email:, password: req.body.password // user schema pre save task hashes this password }); { if (err) return done(err, false, req.flash('error', 'Error saving user.')); var token = new Token({ _userId: user._id, token: crypto.randomBytes(16).toString('hex') }); (err) { if (err) return done(null, false, req.flash('error', err.message)); // Send the email var message = 'Hello,\n\n' + 'Please verify your account by clicking the link: \nhttp:\/\/' + + '\/confirmation\/' + token.token + '.\n'; sendEmail('"Phantom Asset Management"',, 'Account Verification Token', message); }); var time = 14 * 24 * 3600000; req.session.cookie.maxAge = time; //2 weeks req.session.cookie.expires = new Date( + time); req.session.touch(); return done(null, user, req.flash('success', 'A verification email has been sent to ' + + '.')); }); }); }; process.nextTick(findOrCreateUser); }) ); 

当我去/confirmation/:token我得到我的错误404页面,并没有在我的控制台。 只有我看到的是我的debugging器显示该路线的错误404。

Solutions Collecting From Web of "创build帐户电子邮件validation无效"