1
I am creating a user registration system in Nodejs and I need to check if the email entered is already registered, everything is working normally, if I type an existing email it returns the id of the user that uses this email. However, at the time I will write a return on the screen with the res.send("");
the application returns me the title error.
(Is an API)
My code:
app.post('/account/new/validate', function(req, res){
if(typeof req.body.emailRegistro !== 'undefined' && typeof req.body.senhaRegistro !== 'undefined' && typeof req.body.senhaConfirmarRegistro !== 'undefined' && typeof req.body.nomeRegistro !== 'undefined' && typeof req.body.cpfRegistro !== 'undefined' && typeof req.body.nascimentoRegistro !== 'undefined' && typeof req.body.cepRegistro !== 'undefined' && typeof req.body.estadoRegistro !== 'undefined' && typeof req.body.cidadeRegistro !== 'undefined' && typeof req.body.bairroRegistro !== 'undefined' && typeof req.body.ruaRegistro !== 'undefined' && typeof req.body.numeroRegistro !== 'undefined'){
if(req.body.emailRegistro !== "" && req.body.senhaRegistro !== "" && req.body.senhaConfirmarRegistro !== "" && req.body.nomeRegistro !== "" && req.body.cpfRegistro !== "" && req.body.nascimentoRegistro !== "" && req.body.cepRegistro !== "" && req.body.estadoRegistro !== "" && req.body.cidadeRegistro !== "" && req.body.bairroRegistro !== "" && req.body.ruaRegistro !== "" && req.body.numeroRegistro !== ""){
if(req.body.senhaRegistro === req.body.senhaConfirmarRegistro){
var sql = app.config.dbcnx();
var accountModel = app.app.models.accountModel;
//Verificando se o email e o cpf estão em uso
accountModel.verEmailExiste(sql, req.body.emailRegistro, function(error, result){
if(result.length > 0){ res.send("[EmailEmUso]"); }
});
accountModel.verCpfExiste(sql, req.body.cpfRegistro, function(error, result){
if(result.length > 0){ res.send("CpfEmUso"); }
});
res.send("ok");
}else{ res.send("[SenhasDiferentes]"); }
}else{ res.send("[CamposEmBranco]"); }
}else{ res.send("[CamposIndefinidos]"); }
});
Model:
module.exports = function(){
this.verEmailExiste = function(sql, email, callback){
sql.query("SELECT idUser FROM tblUsers WHERE emailUser='" + email + "';", callback);
}
this.verCpfExiste = function(sql, cpf, callback){
sql.query("SELECT idUser FROM tblUsers WHERE cpfUser='" + cpf + "';", callback);
}
return this;
}
I have performed several tests, the sql query is ok, is not returning error, is returning a result.length > 0
and when it comes to res.send("");
of error.
I have already finished a login system in this same format and worked normally.
It worked, I thought when I sent a replay the code stopped automatically, without needing a Return.
– Wesley Nascimento
I thought so too, but after checking with a
console.log
, I realized the shit hehe– Danilo de Oliveira