I am creating a user registration system in NodeJS and I need to check if the email I entered is already registered, everything is working normally, if I type an existing email it returns me the id of the user who uses this email. However, at the time I'm going to write a return on screen with res.send("");
the application returns the error of the title.
(It's 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 already performed several tests, the sql query is ok, it is not returning error, it is returning a result.length > 0
and when it arrives at res.send("");
of error.
I've already completed a login system in that same format and it worked fine.