Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/signUpWeb', function (req, res) {
- var reqBody = req.body;
- var email= reqBody.email;
- var password= reqBody.password;
- var fullName= reqBody.fullName;
- var webDbInsertion = {email: email, password: password, fullName: fullName};
- // note here that "emailExists" is now a parameter in your function callback to your function.
- DButils.checkIfPKexists(connection, "webusersMail", "email", webDbInsertion.email, function( emailExists) {
- if(emailExists == false){
- DButils.insertInfoToDB(connection, "webusersMail" ,webDbInsertion);
- console.log("successfull signup");
- res.send("successfull signup");
- }else{
- console.log("signup failed, email: " + email + " allready exits");
- res.send("signup failed");
- }
- res.end();
- });
- });
- exports.checkIfPKexists= function(dbConnection, tableName, PK, newPK, onDone){ // new parameter 'onDone' is a function
- var query = dbConnection.query('select count(*) as mailPkCount from ' +tableName+ ' where ' +PK+ ' = ?', newPK, function (err, row, result) {
- if (err) {
- console.error(err);
- return;
- }
- var count= row[0].mailPkCount;
- var bool = (count > 0);
- // only changed this here to call the callback with the results
- if( onDone)
- onDone( bool);
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement