From 25839b6895209bfce55baff22059a14ed83e3e1f Mon Sep 17 00:00:00 2001 From: Zachary Lee Date: Thu, 30 Jul 2015 20:35:12 -0500 Subject: [PATCH] FbOAuth fully up and running! Views Rendering correctly. --- client/app/components/signinBox.js | 13 ++++--------- client/app/components/signup.js | 1 - client/app/models/Auth.js | 21 +++++++++++---------- client/app/models/Location.js | 6 +++--- client/app/models/Searches.js | 4 ++-- client/public/sass/mapContainer.scss | 2 +- client/public/style.css | 2 +- firebase.json | 4 +--- package.json | 1 + server/index.js | 21 ++++++++++----------- 10 files changed, 34 insertions(+), 41 deletions(-) diff --git a/client/app/components/signinBox.js b/client/app/components/signinBox.js index 8955d75..90be1ff 100644 --- a/client/app/components/signinBox.js +++ b/client/app/components/signinBox.js @@ -9,7 +9,7 @@ header.controller = function (options) { ctrl.loginUser = function(e) { e.preventDefault(); - Auth.signIn( e.target.email.value, e.target.password.value , function( user, error, uid ) { + Auth.signIn(function( user, error, uid ) { if (user) { toastr["success"]("You are logged in!"); //console.log("User: " + uid); @@ -61,13 +61,8 @@ function renderLoggedOutView(ctrl){ ]) ]), //end div wrapping ul m('form.navbar-form.navbar-right', {onsubmit: ctrl.loginUser}, - [m('form-group', - [m('input.form-control.navbar-login[name="email"][autofocus][id="inputEmail"][placeholder="Email"][required][type="email"]') - ]), - m('form-group', - [m('input.form-control.navbar-login[name="password"][autocomplete="off"][id="inputPassword"][placeholder="Password"][required][type="password"]') - ]), - m('input.btn.btn-default.navbar-login.login-btn[type="submit"][value="Log in"]') + [ + m('input.btn.btn-primary.navbar-login.login-btn[type="submit"][value="Log in with Facebook"]') ]) //end of form ]) //end container }; @@ -88,4 +83,4 @@ var renderLoggedInView = function(ctrl){ m('button.btn.btn-default.logout-btn', {onclick: ctrl.logout}, "Log out")]), ]) ]) //end container -}; \ No newline at end of file +}; diff --git a/client/app/components/signup.js b/client/app/components/signup.js index 8e53c8a..870b30e 100644 --- a/client/app/components/signup.js +++ b/client/app/components/signup.js @@ -100,4 +100,3 @@ function errorView(ctrl) { ]) : null ] } - diff --git a/client/app/models/Auth.js b/client/app/models/Auth.js index 98265de..39bb0d6 100644 --- a/client/app/models/Auth.js +++ b/client/app/models/Auth.js @@ -1,6 +1,6 @@ var m = require('mithril'); var host = "localhost:4000"; -var fb = 'https://craply.firebaseio.com/'; +var fb = 'https://livability.firebaseio.com/'; var ref = new Firebase(fb); /** @@ -18,8 +18,10 @@ window.checkUser = function() { // onAuth is a Firebase method that triggers if there is a change in the status of the authentication status + + ref.onAuth(function(authData) { - if(authData) { + if (authData) { console.log("Authentication state update (+)" + authData); return LoggedIn.userID = authData.uid; } @@ -42,10 +44,10 @@ var Auth = module.exports = { * @returns {userData} */ - createUserAndLogin: function(email, password, cb){ + createUserAndLogin: function(email, password, cb) { return ref.createUser({ - email : email, - password : password + email: email, + password: password }, function(error, userData) { if (error) { //Toastr is a nice flash messaging plugin @@ -72,12 +74,9 @@ var Auth = module.exports = { * @returns {userID} */ - signIn: function(email, password, cb){ + signIn: function(cb) { var loggedIn = null; - return ref.authWithPassword({ - 'email' : email, - 'password' : password - }, function(error, authData) { + return ref.authWithOAuthPopup("facebook", function(error, authData) { if (error) { console.log("Login Failed!", error); cb(null, error, null); @@ -86,6 +85,8 @@ var Auth = module.exports = { LoggedIn.userID = authData.uid; cb(LoggedIn.userID, error, authData.uid); } + }, { + remember: "sessionOnly" }); }, diff --git a/client/app/models/Location.js b/client/app/models/Location.js index aed77f1..84faf95 100644 --- a/client/app/models/Location.js +++ b/client/app/models/Location.js @@ -1,6 +1,6 @@ var m = require('mithril'); var Auth = require('./Auth'); -var fbUrl = 'https://craply.firebaseio.com/'; +var fbUrl = 'https://livability.firebaseio.com/'; var maps = 'https://maps.googleapis.com/maps/api/geocode/'; /** @@ -129,7 +129,7 @@ var Locations = module.exports = { var modelData = function(data) { //Separate data into variables - var inspectCount = 0; + var inspectCount = 0; var commuteData = JSON.parse(data.distance) if (commuteData.status === 'OK'){ @@ -166,4 +166,4 @@ var modelData = function(data) { } else { return response; } -}; \ No newline at end of file +}; diff --git a/client/app/models/Searches.js b/client/app/models/Searches.js index 6ce2bfb..8180ef7 100644 --- a/client/app/models/Searches.js +++ b/client/app/models/Searches.js @@ -1,7 +1,7 @@ var m = require('mithril'); var Auth = require('./Auth'); var _ = require('underscore'); //not really needed as it is used only once -var fbUrl = 'https://craply.firebaseio.com/'; +var fbUrl = 'https://livability.firebaseio.com/'; /** * You shoudld check the Fire base docs to understand the special methods to access data @@ -23,4 +23,4 @@ var Searches = module.exports = { m.redraw(); }) } -}; \ No newline at end of file +}; diff --git a/client/public/sass/mapContainer.scss b/client/public/sass/mapContainer.scss index 97a3123..fc77864 100644 --- a/client/public/sass/mapContainer.scss +++ b/client/public/sass/mapContainer.scss @@ -16,7 +16,7 @@ } .login-btn { - background-color: #435359; + background-color: #3b5998; color: white; } diff --git a/client/public/style.css b/client/public/style.css index 1e99838..632703f 100644 --- a/client/public/style.css +++ b/client/public/style.css @@ -91,7 +91,7 @@ h3, h4 { color: white; } .login-btn { - background-color: #435359; + background-color: #3b5998; color: white; } .navbar-login { diff --git a/firebase.json b/firebase.json index ae75bc7..a9cdc7d 100644 --- a/firebase.json +++ b/firebase.json @@ -2,11 +2,9 @@ "rules": { "users": { "$uid": { - // grants write access to the owner of this user account whose uid must exactly match the key ($uid) ".write": "auth !== null && auth.uid === $uid", - // grants read access to any user who is logged in with an email and password ".read": "auth !== null && auth.provider === 'password'" } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index ae11cba..50705b6 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "browserify": "^10.2.6", "browserify-middleware": "^6.0.0", "express": "^4.13.1", + "firebase": "^2.2.9", "geolib": "^2.0.17", "knex": "^0.8.6", "mithril": "^0.2.0", diff --git a/server/index.js b/server/index.js index ef88e9f..824de85 100644 --- a/server/index.js +++ b/server/index.js @@ -42,8 +42,8 @@ app.get('/client/img/house', function(req, res) { app.post('/distance', function(req, res){ - request('https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + - req.body.address+'&destinations='+req.body.workAddress+'&arrival_time=1438610400&key='+ + request('https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + + req.body.address+'&destinations='+req.body.workAddress+'&arrival_time=1438610400&key='+ credentials.GoogleDistance, function(error, response, body) { if (error) throw error; res.send(body) @@ -100,8 +100,8 @@ app.post('/', function (req, res){ return httpResponseBody; }) .then(function attachCommuteTime(httpResponseBody) { - request('https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + - req.body.address+'&destinations='+req.body.workAddress+'&arrival_time=1438610400&key='+ + request('https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + + req.body.address+'&destinations='+req.body.workAddress+'&arrival_time=1438610400&key='+ credentials.GoogleDistance, function(error, response, body) { if (error) throw error; httpResponseBody.distance = body; @@ -132,7 +132,7 @@ app.post('/', function (req, res){ } }) } - return neighborhoodOptions + return neighborhoodOptions }) // Get the neighborhood information for the requested address .then(function(result){ @@ -150,22 +150,22 @@ app.post('/', function (req, res){ //Property Taxes for neighborhood and Austin average houseData.neighborhood.propTaxNeighborhood = result['Demographics:demographics']['response'][0]['pages'][0]['page'][0]['tables'][0]['table'][0]['data'][0]['attribute'][13]['values'][0]['neighborhood'][0]['value'][0]['_']-0 // Using '-0' to implicitly convert the string value to a number houseData.neighborhood.propTaxCity = result['Demographics:demographics']['response'][0]['pages'][0]['page'][0]['tables'][0]['table'][0]['data'][0]['attribute'][13]['values'][0]['city'][0]['value'][0]['_']-0 - + //Median House Size for neighborhood and Austin average houseData.neighborhood.houseSizeNeighborhood = result['Demographics:demographics']['response'][0]['pages'][0]['page'][1]['tables'][0]['table'][0]['data'][0]['attribute'][2]['values'][0]['neighborhood'][0]['value'][0]-0 // Using '-0' to implicitly convert the string value to a number - houseData.neighborhood.houseSizeCity = result['Demographics:demographics']['response'][0]['pages'][0]['page'][1]['tables'][0]['table'][0]['data'][0]['attribute'][2]['values'][0]['city'][0]['value'][0]-0 - + houseData.neighborhood.houseSizeCity = result['Demographics:demographics']['response'][0]['pages'][0]['page'][1]['tables'][0]['table'][0]['data'][0]['attribute'][2]['values'][0]['city'][0]['value'][0]-0 + //Median Household Income for neighborhood and Austin average houseData.neighborhood.medianIncomeNeighborhood = Math.floor(result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][0]['values'][0]['neighborhood'][0]['value'][0]['_']) houseData.neighborhood.medianIncomeCity = Math.floor(result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][0]['values'][0]['city'][0]['value'][0]['_']) - + //Median Age for neighborhood and Austin average houseData.neighborhood.medianAgeNeighborhood = result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][3]['values'][0]['neighborhood'][0]['value'][0]-0 // Using '-0' to implicitly convert the string value to a number houseData.neighborhood.medianAgeCity = result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][3]['values'][0]['city'][0]['value'][0]-0 //% of households with kids for neighborhood and Austin average houseData.neighborhood.percentWithKidsNeighborhood = (result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][4]['values'][0]['neighborhood'][0]['value'][0]['_']*100).toFixed(3)-0 //Convert decimal to percentage with 3 decimal places - houseData.neighborhood.percentWithKidsCity = (result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][4]['values'][0]['city'][0]['value'][0]['_']*100).toFixed(3)-0 + houseData.neighborhood.percentWithKidsCity = (result['Demographics:demographics']['response'][0]['pages'][0]['page'][2]['tables'][0]['table'][0]['data'][0]['attribute'][4]['values'][0]['city'][0]['value'][0]['_']*100).toFixed(3)-0 } // Attach Zillow data to response httpResponseBody.zillowData = houseData @@ -188,4 +188,3 @@ app.post('/', function (req, res){ var port = process.env.PORT || 4000; app.listen(port); console.log("Listening on port", port); -