var parseCookie = connect.utils.parseCookie;
var Backchannel = require('./bc/backchannel');
-// ********************************
-// For facebook oauth and connect
-// ********************************
-var everyauth = require('everyauth');
-var FacebookClient = require('facebook-client').FacebookClient;
-var facebook = new FacebookClient();
-
-everyauth.debug = true;
-
-// configure facebook authentication
-everyauth.facebook
- .appId('118001624986867')
- .appSecret('c74910f00dea3d083a00572a445af3ae')
- .scope('user_likes,user_photos,user_photo_video_tags,email')
- .entryPath('/fbauth')
- .redirectPath('/profile')
- .findOrCreateUser(function(req) {
- log3(req.user)
- console.log(req.user);
- User.findOne( { }, function( err, user ) {
- log3(err)
- log3(user)
- // if a user exists with that email, call them logged in
- // FIXME: change this to different query on 'fbid'
- if(user) {
- // save the fact that this cookie/session-id is right for this user
- var sid = req.sessionID;
- user.session = sid;
- user.save( function() {
- //req.session.email = 'fuckles';
- sendJson(res, {status: 'ok', message:'Successfully logged in via Fb'});
- });
- }
- });
- });
- //.callbackPath('/fbsucc')
-
-
-
// Depracated
// Used for initial testing
// Static files are loaded when no dynamic views match.
app.use( express.static( __dirname + '/public' ) );
- // EveryAuth fb connect
- app.use( everyauth.middleware() );
-
// Sets the routers middleware to load after everything set
// before it, but before static files.
app.use( app.router );
//sys.puts(school);
if( school ) {
req.school = school;
- //req.school.authorized = authorized;
// If a school is found, the user is checked to see if they are
// authorized to see or interact with anything related to that
// school.
- //school.authorize( user, function( authorized ){
- //});
+ school.authorize( user, function( authorized ){
+ req.school.authorized = authorized;
+ });
next();
} else {
// If no school is found, display an appropriate error.
// in those schools.
// Public with some private information
app.get( '/schools', checkAjax, loadUser, function( req, res ) {
+ sys.puts('loading schools');
+ console.log(req.user);
var user = req.user;
var schoolList = [];
// Logut user
app.get( '/logout', checkAjax, function( req, res ) {
+ sys.puts("logging out");
var sid = req.sessionID;
// Find user by session id
});
var backchannel = new Backchannel(app, io.of('/backchannel'), {
+ // TODO: if lecture belongs to course (find pinker's courseId) pass a 'no-answers' true/false
subscribe: function(lecture, send) {
Post.find({'lecture': lecture}, function(err, posts) {
send(posts);
var mailer = new Mailer( app.set('awsAccessKey'), app.set('awsSecretKey') );
-everyauth.helpExpress(app);
-
app.listen( serverPort, function() {
console.log( "Express server listening on port %d in %s mode", app.address().port, app.settings.env );