Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/signUp', function(req, res) {
- var username = req.body.username;
- var password = req.body.password;
- db.collection('users').find({username: username})
- .then((user) => {
- console.log(user);
- if(user[0]){
- console.log('bad request');
- res.status(400).end("bad request");
- res.set("Connection", "close");
- } else {
- return Utils.hashPassword(password)
- }
- })
- .then(function(hash){
- console.log('Running hash promise')
- return db.collection('users').insert({username: username, password: hash});
- })
- .then(function(obj){
- console.log("Data returned from inserting:", obj);
- var sessionId = Utils.createSessionId();
- console.log("Line 44:", sessionId);
- return db.collection('sessions').insert({id: obj._id, sessionId: sessionId});
- })
- .then(function(obj){
- console.log("Data returned from inserting into sessions:", obj)
- res.cookie("session_id", obj.sessionId, { maxAge: 900000, httpOnly: false})
- res.send("yay!");
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement