diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-22 05:24:40 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-22 05:24:40 +0000 |
| commit | 070153f4555e16d44e538e305f85eb0552e9044e (patch) | |
| tree | bd956bc68097351e327b532615ba951beeb7eebf | |
| parent | dcde34904acf5722a19559bb06052061723c2110 (diff) | |
Minor change to add_user
| -rw-r--r-- | node_simple.js | 27 | ||||
| -rw-r--r-- | routes/index.js | 1 |
2 files changed, 14 insertions, 14 deletions
diff --git a/node_simple.js b/node_simple.js index 4c290f5..99a187e 100644 --- a/node_simple.js +++ b/node_simple.js @@ -130,22 +130,23 @@ exports.add_user = function (fields, callbackUser) { var users = db.collection('users'); var logins = db.collection('logins'); + // Add users, and login through callbacks users.insertOne( user_data, function (err) { - if (err) callbackUser(false, true, "Unable to add user."); - /*else { - console.log("user has been added to users"); - callbackUser(true, false, "User has been added."); - }*/ + if(err){ + callbackUser(false, true, "Unable to add user."); + }else { // user insert successfull + logins.insertOne(login_data, function (err) { + if (err) { + callbackUser(false, true, "Login has not been added."); + } else { // login insert successfull + callbackUser(true, false, "User has been added."); + db.close(); + } + }); + } }); - logins.insertOne( login_data, function (err) { - if (err) callbackUser(false, true, "Login has not been added."); - /*else{ - callbackUser(true, false, "Login added."); - }*/ - }); - callbackUser(true, false, "User has been added."); - db.close(); + }) .catch(function (err) { callbackUser(false, true, "Unable to connect."); diff --git a/routes/index.js b/routes/index.js index f44b175..b6db0ca 100644 --- a/routes/index.js +++ b/routes/index.js @@ -211,7 +211,6 @@ function toProperCase(string) { return string.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); } - /* Takes an input string delimited by commas, will split by comma and trim white * spaces. Consider callback. */ |
