diff --git a/database/index.js b/database/index.js index 5b29e5f..24ce303 100644 --- a/database/index.js +++ b/database/index.js @@ -53,7 +53,7 @@ const checkForUser = function (facebookId) { return pool.query('SELECT * FROM users WHERE user.fb_id = $1', [facebookId]); }; const insertNewFbUser = function (newUser) { - return pool.query('INSERT INTO users (fb_id, fb_name, prof_pic) VALUES ($1, $2)', [newUser.id, newUser.displayName, newUser.photo]); + return pool.query('INSERT INTO users (fb_id, fb_name, prof_pic) VALUES ($1, $2, $3)', [newUser.id, newUser.displayName, newUser.photo]); } const getUserProfile = function (userId) { return pool.query('SELECT users.user_id, users.name, users.prof_pic, users.description FROM users \ diff --git a/server/LogInServerModule.js b/server/LogInServerModule.js index d308458..09983f4 100644 --- a/server/LogInServerModule.js +++ b/server/LogInServerModule.js @@ -159,12 +159,12 @@ app.use(express.static(__dirname + '/../client/dist')); //routes here -app.get('/logon', function (req, res) { - console.log('request', req.body.params) - res.json(req.body.params); - }); +// app.get('/logon', function (req, res) { +// console.log('request', req.body.params) +// res.json(req.body.params); +// }); -app.get('/login', +app.get('/login/facebook', // will keep this in case we need to track request params later // function (req, res) { diff --git a/server/controller.js b/server/controller.js index 201d824..f9bf54e 100644 --- a/server/controller.js +++ b/server/controller.js @@ -33,7 +33,25 @@ module.exports = { console.log('getUsersFollowing had an error', err); }); }, + fbLogin: function(req, res) { + db.checkForUser(res.body.id) + .then((results) => { + let user = results.rows; + if (user.length === 0) { + let newUser = { + "id": res.body.id, + "displayName": res.body.displayName, + "photo": res.body.photos[0].value + } + db.insertNewFbUser(newUser) + .then(res.sendStatus(201)) + .catch((err) => { + console.log('insert new fb user had an error', err); + }) + } + }) + }, usersFollowers: function(req, res) { db.getUsersFollowers(1) //CURRENTLY HARD CODED USER ID, change to req.body .then((results) => {