Advertisement
Guest User

Untitled

a guest
Jul 8th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. app.post('/signUp', function(req, res) {
  2. var username = req.body.username;
  3. var password = req.body.password;
  4.  
  5. db.collection('users').find({username: username})
  6. .then((user) => {
  7. console.log(user);
  8. if(user[0]){
  9. console.log('bad request');
  10. res.status(400).end("bad request");
  11. res.set("Connection", "close");
  12. } else {
  13. return Utils.hashPassword(password)
  14. }
  15. })
  16. .then(function(hash){
  17. console.log('Running hash promise')
  18. return db.collection('users').insert({username: username, password: hash});
  19. })
  20. .then(function(obj){
  21. console.log("Data returned from inserting:", obj);
  22. var sessionId = Utils.createSessionId();
  23. console.log("Line 44:", sessionId);
  24. return db.collection('sessions').insert({id: obj._id, sessionId: sessionId});
  25. })
  26. .then(function(obj){
  27. console.log("Data returned from inserting into sessions:", obj)
  28. res.cookie("session_id", obj.sessionId, { maxAge: 900000, httpOnly: false})
  29. res.send("yay!");
  30. })
  31. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement