Skip to content

Commit

Permalink
FbOAuth fully up and running! Views Rendering correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
zckly authored and AnkyrinRepeat committed Jul 31, 2015
1 parent 2afa293 commit 25839b6
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 41 deletions.
13 changes: 4 additions & 9 deletions client/app/components/signinBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
};
Expand All @@ -88,4 +83,4 @@ var renderLoggedInView = function(ctrl){
m('button.btn.btn-default.logout-btn', {onclick: ctrl.logout}, "Log out")]),
])
]) //end container
};
};
1 change: 0 additions & 1 deletion client/app/components/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ function errorView(ctrl) {
]) : null
]
}

21 changes: 11 additions & 10 deletions client/app/models/Auth.js
Original file line number Diff line number Diff line change
@@ -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);

/**
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -86,6 +85,8 @@ var Auth = module.exports = {
LoggedIn.userID = authData.uid;
cb(LoggedIn.userID, error, authData.uid);
}
}, {
remember: "sessionOnly"
});
},

Expand Down
6 changes: 3 additions & 3 deletions client/app/models/Location.js
Original file line number Diff line number Diff line change
@@ -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/';

/**
Expand Down Expand Up @@ -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'){
Expand Down Expand Up @@ -166,4 +166,4 @@ var modelData = function(data) {
} else {
return response;
}
};
};
4 changes: 2 additions & 2 deletions client/app/models/Searches.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,4 +23,4 @@ var Searches = module.exports = {
m.redraw();
})
}
};
};
2 changes: 1 addition & 1 deletion client/public/sass/mapContainer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

.login-btn {
background-color: #435359;
background-color: #3b5998;
color: white;
}

Expand Down
2 changes: 1 addition & 1 deletion client/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ h3, h4 {
color: white; }

.login-btn {
background-color: #435359;
background-color: #3b5998;
color: white; }

.navbar-login {
Expand Down
4 changes: 1 addition & 3 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 10 additions & 11 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +132,7 @@ app.post('/', function (req, res){
}
})
}
return neighborhoodOptions
return neighborhoodOptions
})
// Get the neighborhood information for the requested address
.then(function(result){
Expand All @@ -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
Expand All @@ -188,4 +188,3 @@ app.post('/', function (req, res){
var port = process.env.PORT || 4000;
app.listen(port);
console.log("Listening on port", port);

0 comments on commit 25839b6

Please sign in to comment.