lundi 9 mars 2015

Verification email with token in passport.js

I just looking for solution which makes verification email with token for my local autentification in passport.js Is there some plugin or component for node which can make me verification easyer? Or I have to do it myself?


My controller



exports.postSignup = function(req, res, next) {
req.assert('email', 'Email is not valid').isEmail();
req.assert('password', 'Password must be at least 4 characters long').len(4);
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);

var errors = req.validationErrors();

if (errors) {
req.flash('errors', errors);
return res.redirect('/signup');
}

var user = User.build({
email: req.body.email,
password: req.body.password,
});

User
.find({ where: { email: req.body.email } })
.then(function(existingUser){
if (existingUser) {
req.flash('errors', { msg: 'Account with that email address already exists.' });
return res.redirect('/signup');
}

user
.save()
.complete(function(err){
if (err) return next(err);
req.logIn(user, function(err){
if (err) return next(err);
res.redirect('/');
});
});
}).catch(function(err){
return next(err);
});
};


Thanks for any opinion!


Aucun commentaire:

Enregistrer un commentaire