Skip to content

Commit

Permalink
Post bugs fixed and cra server combined with primary server
Browse files Browse the repository at this point in the history
  • Loading branch information
bpiv400 committed Dec 10, 2017
1 parent a0dc727 commit a2c1cf5
Show file tree
Hide file tree
Showing 106 changed files with 7,307 additions and 99 deletions.
36 changes: 36 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var ejs = require('ejs');
var passport = require('passport')
, FacebookStrategy = require('passport-facebook').Strategy;

var index = require('./routes/index');
var users = require('./routes/users');
Expand All @@ -13,9 +15,32 @@ var view = require('./routes/view');
var images = require('./routes/images');
var search = require('./routes/search');
var results = require('./routes/results');
var login = require('./routes/login');

var userDb = require('./data/users.js');

var FACEBOOK_APP_ID = '1514772795286498';
var FACEBOOK_APP_SECRET = 'cf0f074ea3e1a76939f5ca24792dcee9';

passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3001/auth/facebook/callback",
profileFields: ['id', 'displayName', 'emails']
},
function(accessToken, refreshToken, profile, done) {
userDb.findOrCreate(profile, function(err, user) {
if (err) {
return done(err);
} else {
done(null, user);
}
});
})
);

var handleError = require('./middlewares/handleError.js');
var loginCheck = require('./middlewares/loginCheck.js');

var app = express();

Expand All @@ -32,11 +57,22 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//app.use(loginCheck);

app.use('/', index);
// app.use('/users', users);
app.use('/create', create);
app.use('/view', view);
app.use('/login', login);
app.get('/auth/facebook', passport.authenticate('facebook'));
// Facebook will redirect the user to this URL after approval. Finish the
// authentication process by attempting to obtain an access token. If
// access was granted, the user will be logged in. Otherwise,
// authentication has failed.
app.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/',
failureRedirect: '/login' }));

app.use('/images', images);
app.use('/search', search);
app.use('/results', results);
Expand Down
2 changes: 1 addition & 1 deletion data/db/WiredTiger.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ WiredTiger 2.9.2: (December 23, 2016)
WiredTiger version
major=2,minor=9,patch=2
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,block_allocation=best,block_compressor=,cache_resident=false,checkpoint=(WiredTigerCheckpoint.148=(addr="018081e44ae82d968181e42c703ca38281e41ca436b0808080e3010fc0e23fc0",order=148,time=1512897034,size=28672,write_gen=294)),checkpoint_lsn=(4,4631040),checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1)
access_pattern_hint=none,allocation_size=4KB,app_metadata=,block_allocation=best,block_compressor=,cache_resident=false,checkpoint=(WiredTigerCheckpoint.176=(addr="018081e4773c38448181e42c703ca38281e41ca436b0808080e3010fc0e23fc0",order=176,time=1512945130,size=28672,write_gen=350)),checkpoint_lsn=(4,17107968),checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1)
Binary file modified data/db/WiredTiger.wt
Binary file not shown.
Binary file modified data/db/collection-0-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/collection-10-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/collection-8-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/index-1-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/index-11-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/index-9-452669459990989440.wt
Binary file not shown.
Binary file modified data/db/journal/WiredTigerLog.0000000004
Binary file not shown.
Binary file modified data/db/sizeStorer.wt
Binary file not shown.
273 changes: 273 additions & 0 deletions data/log/mongod.log

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion data/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ mongoose.connect('mongodb://127.0.0.1:27017/penn-leases', function (err) {
var db = mongoose.connection;
var possTerms = ['Spring 2018', 'Summer 2018', 'Fall 2018'];

var userSchema = new mongoose.Schema({
name: {type: String, required : true},
email: {type: String, required : true},
provider: {type: String, required : true},
profile: {type: Object, required: true},
following: {type:[{type: mongoose.Schema.Types.ObjectId, ref: 'Listing'}],
required : true, default : []},
posted: {type:[{type: mongoose.Schema.Types.ObjectId, ref: 'Listing'}],
required : true, default : []},
});

var listingSchema = new mongoose.Schema({
housingType: {type : String, required : true, enum: ['House', 'Apartment Building']},
term: {type: [{type: String, enum: possTerms}], required : true,
Expand All @@ -36,9 +47,12 @@ var listingSchema = new mongoose.Schema({
}*/
},
buildingName : {type: String},
name: {type: String, required: true, trim: true},
email: {type: String, required: true, trim: true},
price: {type: Number, required: true, min: 0},
furnished: {type: Boolean, required: true},
size: {type: Number, min: 0},
date: {type: Date, default : Date.now},
occupancy: {type: Number, validate: {
validator : function (value) {
return value % 1 === 0 && value > 0;
Expand Down Expand Up @@ -83,9 +97,10 @@ var addressSchema = new mongoose.Schema({
var Listings = mongoose.model('Listing', listingSchema);
var Address = mongoose.model('Address', addressSchema);
var Photo = mongoose.model('Photo', photoSchema);

var User = mongoose.model('User', userSchema);
module.exports = {
Listings: Listings,
User: User,
Photo: Photo,
Address: Address,
mongoose: mongoose,
Expand Down
31 changes: 31 additions & 0 deletions data/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var mongo = require('./mongo');

module.exports = {
findOrCreate(userData, callback) {
mongo.User.findOne({'facebook.id' : userData.id}, function(err, user) {
if (err) {
return callback(err);
} else if (!user) {
console.log(userData);
user = new mongo.User({
name: userData.displayName,
email: userData.email,
provider: 'facebook',
profile: userData._json,
following: [],
posted: []
});
user.save(function(err) {
if (err) {
console.log(err);
} else {
console.log('user saved correctly');
}
return callback(err, user);
});
} else {
return callback(err, user);
}
});
}
}
21 changes: 21 additions & 0 deletions middlewares/loginCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

// TODO: Write the handleError middleware.
// This function must be an express error handling middleware

var loginCheck = function (req, res, next) {
console.log(req.user);
if (!req.user) {
console.log(req.path);
if (req.path !== '/login' &&
req.path !== '/auth/facebook' &&
req.path !== '/auth/facebook/' &&
req.path !== 'auth/facebook/callback' &&
req.path !== 'auth/facebook/callback/') {
res.redirect('/login');
}
}
next();
};

// Export the middleware function for use in app.js
module.exports = loginCheck;
1 change: 1 addition & 0 deletions node_modules/oauth/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions node_modules/oauth/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/oauth/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

190 changes: 190 additions & 0 deletions node_modules/oauth/Readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a2c1cf5

Please sign in to comment.