daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function doRegister(req,res){
  2.     var username = req.body.username;
  3.     var password = req.body.password;
  4.     new Promise((resolve,reject) => {
  5.         connection.addUserToDB(username, password, success => {
  6.             if (success) {
  7.                 req.session.loggedin = username;
  8.                 res.redirect("/");
  9.                 resolve("The user " + username + "has been added to the database");
  10.             }
  11.             else{
  12.                 res.render("form", {
  13.                     title:"Register",
  14.                     action: "/doRegister",
  15.                     btnText:"Register",
  16.                     error:"Failed to register " + username
  17.                 });
  18.                 reject("The user " + username + " was not added to the database");
  19.             }
  20.         });
  21.     })
  22.         .then(data => {
  23.             console.log(data); return data;
  24.         })
  25.         .catch(data => {
  26.             console.error(data); return data;
  27.         })
  28.         .then(data => {
  29.             logMessage(data)
  30.         });
  31.  
  32.  
  33. }
  34.  
  35. function logMessage(data){
  36.     fs.appendFile(logFile, data + "\n", function (error){
  37.         if (error) throw error;
  38.     });
  39.     console.log(data);
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top