forked from choucalate/tncwebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d962ea
Showing
2,311 changed files
with
323,066 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var express = require('express'), | ||
routes = require('./routes'), | ||
everyauth = require('everyauth'), | ||
conf = require('./myconfig'), | ||
graph = require('fbgraph'), | ||
picture = require('./models/picture').picture, | ||
mongoose = require('mongoose'), | ||
connect = require('connect') | ||
port = (process.env.PORT || 8080); | ||
|
||
// Configuration for everyauth | ||
//THIS IS CALLED WHEN /AUTH/FACEBOOK GETS CALLED | ||
everyauth | ||
.appId(conf.client_id) | ||
.appSecret(conf.client_secret) | ||
.scope(conf.scope) | ||
.fields('picture') | ||
.handleAuthCallbackError(function (req, res) { | ||
// If a user denies your app, Facebook will redirect the user to | ||
// /auth/facebook/callback?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request. | ||
console.log("there's been an error"); | ||
}) | ||
.findOrCreateUser(function (session, accessToken, accessTokenExtra, fbUserMetadata) { | ||
// console.log("find or create user"); | ||
graph.setAccessToken(accessToken); | ||
graph.get('me/?fields=photos', function (err, data) { | ||
if(err) return console.log("err: " + err); | ||
|
||
routes.saveAll(data, function(error) { | ||
if(err) return console.log(JSON.stringify(err, null, '\t')); | ||
console.log("finished"); | ||
return; | ||
}) | ||
}); | ||
var user = { | ||
id: 0, | ||
'facebook': fbUserMetadata | ||
}; | ||
|
||
return user; | ||
}) | ||
.redirectPath('/'); | ||
|
||
var app = express(); | ||
|
||
/*ADD THE MONGODB*/ | ||
var uristring = process.env.MONGOHQ_URL || | ||
process.env.MONGOLAB_URI || | ||
'mongodb://localhost/picGallery1'; | ||
|
||
//mongoose conneecting string logging to the out | ||
mongoose.connect(uristring, function(err, res) { | ||
if(err) { | ||
console.log("ERROR occurred connecting to :" + uristring + '. ' + err); | ||
} else { | ||
console.log("MONGO connected! here: " + uristring); | ||
|
||
} | ||
}); | ||
|
||
//the db connection on error or opened | ||
var db = mongoose.connection; | ||
|
||
db.on('error', console.error.bind(console, 'connection error:')); | ||
db.once('open', function callback() { | ||
console.log("MONGO open!"); | ||
}); | ||
|
||
app.configure(function () { | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'jade'); | ||
app.set('view options', { | ||
layout: false | ||
}); | ||
app.use(express.cookieParser()); | ||
app.use(express.session({ | ||
secret: "shhhhhhhhh!" | ||
})); | ||
app.use(connect.static(__dirname + '/public')); | ||
app.use(everyauth.middleware()); | ||
}); | ||
|
||
app.configure('development', function () { | ||
app.use(express.errorHandler({ | ||
dumpExceptions: true, | ||
showStack: true | ||
})); | ||
}); | ||
|
||
app.configure('production', function () { | ||
app.use(express.errorHandler()); | ||
}); | ||
|
||
// Routes | ||
|
||
app.get('/', routes.index); | ||
|
||
app.get('/mygallery', function(req, res) { | ||
picture.findLimited(400, 0, function(err, data) { | ||
res.end(JSON.stringify(data, null, '\t')); | ||
}); | ||
// routes.getSomeLinks(req, res, function(err, data) { | ||
// if(err) var pic = "picture cannot be found"; | ||
// else { | ||
// var picArr = data; | ||
// //console.log(JSON.stringify(picArr[0].images[4].source, null, '\t')); | ||
// res.render('login2.jade', { | ||
// title: "WHOO", | ||
// arr: picArr | ||
// }); | ||
// } | ||
// }); | ||
}); | ||
|
||
app.get('/fakerender', function(req, res) { | ||
picture.findLimited(100, 0, function(err, data) { | ||
res.render('login2.jade', { | ||
title: "WHOO", | ||
arr: data | ||
}); | ||
}); | ||
}); | ||
|
||
app.get('/pictures', function(req, res) { | ||
picture.findLimited(100, 0, function(err, data) { | ||
|
||
var items = ""; | ||
|
||
res.render('index.jade', { | ||
title: "WHOO", | ||
myitems: items, | ||
arr: data | ||
}); | ||
}); | ||
}); | ||
|
||
app.listen(port, function () { | ||
console.log("Express server listening on port %d in %s mode", port, app.settings.env); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
var mongoose = require('mongoose'), | ||
Schema = mongoose.Schema, | ||
ObjectId = Schema.ObjectId, | ||
async = require('async'); | ||
|
||
var picSchema = new Schema({ | ||
picId: String, | ||
pic_link: String, | ||
pic_source: String, | ||
height: Number, | ||
width: Number, | ||
images: [{ | ||
height: Number, | ||
width: Number, | ||
source: String | ||
}], | ||
link: String, | ||
icon: String, | ||
likes: [String], //names | ||
tags: [String], //names | ||
}); | ||
|
||
picSchema.statics.addPic = function (data, cb) { | ||
|
||
picture.find({ | ||
picId: data.id | ||
}, function (err, result) { | ||
if (err) return cb("failed before locating id: " + err); | ||
if (result.length != 0) { | ||
var msg = "FOUND A DUPLICATE WITH THIS LINK: " + data.link; | ||
//console.log(msg); | ||
return cb(null, msg); | ||
} | ||
//images array | ||
var images = []; | ||
for (i in data.images) { | ||
var sub = data.images[i]; | ||
var image = { | ||
height: sub.height, | ||
width: sub.width, | ||
source: sub.source | ||
}; | ||
images.push(image); | ||
} | ||
//console.log("images: " + JSON.stringify(images, null, '\t')); | ||
|
||
//likes and tags | ||
var likes = []; | ||
if (data.likes) { | ||
for (i in data.likes.data) | ||
likes.push(data.likes.data[i].name); | ||
//console.log("printing likes: " + JSON.stringify(likes, null, '\t')); | ||
} | ||
|
||
var tags = []; | ||
if (data.tags) { | ||
for (i in data.tags.data) | ||
tags.push(data.tags.data[i].name); | ||
//console.log("printing tags: " + JSON.stringify(tags, null, '\t')); | ||
} | ||
/*if(data.tags || data.likes) | ||
console.log("^^ from data.id: " + data.link); | ||
return;*/ | ||
var pic = new picture({ | ||
picId: data.id, | ||
pic_link: data.picture, | ||
height: data.height, | ||
width: data.width, | ||
images: images, | ||
link: data.link, | ||
icon: data.icon, | ||
likes: likes, | ||
tags: tags | ||
}); | ||
pic.save(function (err) { | ||
if (err) return cb(err); | ||
return cb(null, "success message"); | ||
}); | ||
}); | ||
} | ||
|
||
picSchema.statics.findPicsFromAlbum = function (album_name, cb) { | ||
picture.find({ | ||
album: album_name | ||
}, function (err, data) { | ||
cb(err, data); | ||
}); | ||
} | ||
|
||
picSchema.statics.findAll = function (cb) { | ||
var q = picture.find({}).limit(20); | ||
q.execFind(function (err, data) { | ||
// console.log(data); | ||
cb(null, data); | ||
/*console.log("length: " + data); | ||
if(err) cb(err); | ||
else cb(null, data);*/ | ||
}); | ||
} | ||
picSchema.statics.findLinks = function (limit, index, cb) { | ||
var q = picture.find({}).limit(limit).skip(index); | ||
q.execFind(function (err, data) { | ||
if (err) cb(err); | ||
var allLinks = []; | ||
for (i in data) | ||
allLinks.push(data[i]); | ||
cb(null, allLinks); | ||
}); | ||
} | ||
|
||
picSchema.statics.findLimited = function (limit, index, cb) { | ||
var q = picture.find({}).limit(limit).skip(index); | ||
q.execFind(function (err, data) { | ||
if (err) cb(err); | ||
else cb(null, data); | ||
}); | ||
} | ||
var picture = mongoose.model('picture', picSchema); | ||
exports.picture = picture; | ||
//exports.schema = peopleSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
conf = { | ||
client_id: '763712290322636' | ||
, client_secret: '4a01130e4fed848bf91187ec098515da' | ||
, scope: 'user_photos' | ||
}; | ||
|
||
module.exports = conf; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.