Hello, I'm developing a login system, but I'd like to improve something. When I register a user, and type their name, address, etc., and make the request of the form, it returns all the empty inputs. Like the GIF below ...
Notice in the above GIF that after I hit Register , the inputs are left blank . That would be the point. I do not want the inputs to be empty.
Well, below is the snippet of code I used. I use Passport.js to authenticate the user.
passport.use('local.signup', new localStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
}, function(req, email, password, done){
req.checkBody('email', 'E-mail inválido').notEmpty().isEmail();
req.checkBody('password', 'Insira uma senha').notEmpty();
req.checkBody('password', 'Senha inválida').isLength({ min: 5 }).withMessage('Senha deve ter no mínimo 5 caracteres').equals(req.body.password1).withMessage('Senhas não conferem');
var errors = req.validationErrors();
if(errors) {
var messages = [];
errors.forEach(function(error){
messages.push(error.msg);
});
return done(null, false, req.flash('error', messages));
}
User.findOne({'email': email}, function(err, user){
if(err) {
return done(err);
}
if(user) {
return done(null, false, {message: 'Email já está sendo usado!'});
}
var newUser = new User();
newUser.email = email;
newUser.password = newUser.encryptPassword(password);
newUser.save(function(err, result){
if(err) {
return done(err);
}
return done(null, newUser);
});
});
}));