3
Hello, I am developing a login system, but I would like to improve something. When I register a user, and type his name, address, etc., and request the form, he returns all empty inputs. As in the GIF below...
Notice on the GIF above that after I press on Register, the inputs go blank. That would be the point. I don’t want the inputs to be empty.
Well, below follows the excerpt of the 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);
});
});
}));
I’ve had this doubt, you handle the password difference on the right server side, one way out is to treat this difference on the client side with javascript using click event or something similar. Another way out is to treat the difference on the server but send the data back to the page and work the insertion of this data with
if()
.– Chance
This "register" button would happen to be
type='submit'
? Post your html and javascript too please.– Máttheus Spoo
That’s right. It’s a common HTML form. I already put it in the code here.
– Victor