Advertisement
sja91

Untitled

Nov 15th, 2015
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.post('/signUpWeb', function (req, res) {
  2.   var reqBody = req.body;
  3.   var email= reqBody.email;
  4.   var password= reqBody.password;
  5.   var fullName= reqBody.fullName;
  6.   var webDbInsertion  = {email: email, password: password, fullName: fullName};
  7.  
  8.   // note here that "emailExists" is now a parameter in your function callback to your function.
  9.   DButils.checkIfPKexists(connection, "webusersMail", "email", webDbInsertion.email, function( emailExists) {
  10.  
  11.     if(emailExists == false){
  12.     DButils.insertInfoToDB(connection, "webusersMail" ,webDbInsertion);
  13.     console.log("successfull signup");
  14.     res.send("successfull signup");
  15.     }else{
  16.     console.log("signup failed, email: " + email + " allready exits");
  17.     res.send("signup failed");
  18.     }
  19.     res.end();
  20.  
  21.   });
  22. });
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. exports.checkIfPKexists=  function(dbConnection, tableName, PK, newPK, onDone){ // new parameter 'onDone' is a function
  31.     var query = dbConnection.query('select count(*) as mailPkCount from ' +tableName+ ' where ' +PK+ ' = ?', newPK, function (err, row, result) {  
  32.     if (err) {
  33.       console.error(err);
  34.       return;
  35.     }
  36.     var count= row[0].mailPkCount;
  37.     var bool = (count > 0);
  38.     // only changed this here to call the callback with the results
  39.     if( onDone)
  40.     onDone( bool);
  41.     });
  42.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement