app.configure(function () { app.set('connstring', 'mongodb://alex.mongohq.com:10081/jitsusessions'); mongoose.connect(app.get('connstring'), {user: process.env.M_USER, pass: process.env.M_PASS}); var bio = require('./models/bio')(mongoose); app.set('port', process.env.PORT || 3000); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser('your secret here')); app.use(express.session({ secret:'topsecret', store:new MongoStore({ url:app.set('connstring'), password:process.env.M_PASS, username:process.env.M_USER }) })); app.use(auth({ strategies:[ auth.Facebook({ appId:process.env.FB_APP_ID, appSecret:process.env.FB_APP_SECRET, scope:"email", callback:'https://jonlarsson.nodejitsu.com/auth/facebook_callback' }) ], trace:true, logoutHandler:require("connect-auth/lib/events").redirectOnLogout("/")})); app.use(example_auth_middleware()); app.use('/logout', function (req, res, params) { req.logout(); // Using the 'event' model to do a redirect on logout. }); if ('production' === app.get('env')) { app.all("/api/*", function(req, res, next) { if (req.isAuthenticated()) { next(); } else { return res.send(401, {user: "******"}); } }); } app.use('/api/user', function(req, res) { if (req.isAuthenticated()) { res.send(req.getAuthDetails().user); } else { res.send({user : "******"}); } }); for(modelName in bio.api) { app.get("/api/" + modelName + "s", bio.api[modelName].list); app.post("/api/" + modelName + "s", bio.api[modelName].post); app.put("/api/" + modelName + "s/:id", bio.api[modelName].put); app.get("/api/" + modelName + "s/:id", bio.api[modelName].get); app.delete("/api/" + modelName + "s/:id", bio.api[modelName].delete); app.use(express.static(path.join(__dirname, 'public'))); } });
var FacebookConnect = function(app, SETTINGS, onAuthentication) { if(!SETTINGS.ID) { throw Error('facebook object literal is missing id'); } if(!SETTINGS.SECRET) { throw Error('facebook object literal is missing secret'); } if(!SETTINGS.CALLBACK) { throw Error('facebook object literal is missing callback'); } this.SETTINGS = SETTINGS; // Method to handle a sign-in with a specified method type, and a url to go back to ... var CALLBACK = SETTINGS.CALLBACK.replace(/\/$/, ''); // remove trailing slash. app.use(auth( [ auth.Facebook({ appId : SETTINGS.ID, appSecret: SETTINGS.SECRET, callback: CALLBACK + '/auth/facebook', scope: 'email'}) ]) ); app.get('/auth/facebook', function(req,res) { req.authenticate(['facebook'], function(error, authenticated) { onAuthentication(req, res, authenticated); }); }); app.get('/auth/logout', function(req, res, params) { req.logout(); res.writeHead(303, { 'Location': "/" }); res.end(''); }); };
app.configure(function(){ app.set('app_info', common.loadConfig('app')); app.get('app_info').url_start; app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser()); app.use(express.session({ secret: app.get('app_info').sess_secret, cookie: {maxAge: 86400000 * 200} // 200 days. })); var auth_config = common.loadConfig('auth'); app.use(auth({ strategies : [ auth.Facebook(auth_config.facebook) ], trace: true, logoutHandler: require('connect-auth/lib/events').redirectOnLogout("/") }) ); app.use(app.router); app.use(require('less-middleware')({ src: __dirname + '/public' })); app.use(express.static(path.join(__dirname, 'public'))); });
app.configure('development', function(){ app.use(express.static(__dirname + '/../public')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); var fbCallbackAddress = "http://test.artintheopen.no.de:7777/signin_callback" app.use(auth( [ auth.Facebook({appId : keys.fbId, appSecret: keys.fbSecret, scope: "email", callback: fbCallbackAddress}) ]) ); //This app.use should be called after the auth app.use(app.router); });
app.configure('production', function(){ var oneYear = 31557600000; //app.use(express.static(__dirname + '/../public', { maxAge: oneYear })); app.use(express.static(__dirname + '/../public')); app.use(express.errorHandler()); var fbCallbackAddress = "http://artintheopen.no.de/signin_callback" app.use(auth( [ auth.Facebook({appId : keys.fbId, appSecret: keys.fbSecret, scope: "email", callback: fbCallbackAddress}) ]) ); //This app.use should be called after the auth app.use(app.router); });
app.configure(function(){ // Set up our default templating and template processor // we need to register a .html handler or we need to parse a .ejs file app.set( "view engine", "ejs" ); app.set( "views", __dirname + '/views' ); app.use( express.favicon() ); app.use( express.cookieParser() ); app.use( auth([ auth.Twitter({consumerKey: api.TWITTER_CONSUMER, consumerSecret: api.TWITTER_SECRET}) , auth.Facebook({appId : api.FACEBOOK, appSecret: api.FACEBOOK_SECRET, scope: "email", callback: 'someurl'}) ]) ) app.use( express.static( __dirname + '/static' ) ); });
app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); // app.use(express.methodOverride()); // app.use(app.router); app.use(express.static(__dirname + '/public')); app.use(express.cookieParser()); app.use(express.session({secret: cookieSecret})); app.use(auth( [ // auth.Facebook({appId: fbId, appSecret: fbSecret, scope: "email", callback: fbCallbackAddress}) auth.Facebook({appId: fbId, appSecret: fbSecret, callback: fbCallbackAddress}) ])); });
this.initApp = function (app) { app.use( auth({ strategies: [ auth.Twitter({consumerKey: config.auth.twitter.consumerkey, consumerSecret: config.auth.twitter.consumersecret}), auth.Facebook({appId: config.auth.facebook.appid, appSecret: config.auth.facebook.appsecret, scope: "email", callback: 'http://webapi-video-paste.dotcloud.com/auth/facebook/login'}), auth.Google2({appId: config.auth.google.clientid, appSecret: config.auth.google.clientsecret, callback: 'http://webapi-video-paste.dotcloud.com/auth/google/login', requestEmailPermission: true}) ], trace: true }) ); var route_data = { "controller": "login", "action": "login", "url": "", "method": "get", "description": "service login", "isRegExp": false }; controller.initRoute(app, route_data, 'auth/:service/login'); };
var logout_handler = require("connect-auth/lib/events").redirectOnLogout("/discussions"); var account = require('./routes/account'); var fb_bot_middleware = require('./routes/fb_bot/middleware'); // ########### Static parameters ########### var IS_ADMIN = /admin|staging/.test(process.env['NODE_ENV'] || ''); var IS_PROCESS_CRON = (process.argv[2] === 'cron'); var IS_PROCESS_WEB = !IS_PROCESS_CRON; var auth_middleware = auth({ strategies: [ account.SimpleAuthentication(), account.FbServerAuthentication(), auth.Facebook(config.fb_auth_params) ], trace: true, logoutHandler: logout_handler }); // ########### Static parameters ########### // Run some compilations require('./tools/compile_templates'); require('./tools/compile_dust_templates'); // ######### connect to DB ######### if (!mongoose.connection.host) {
app.param('fid', loadFlux); app.use(express.logger('dev')); app.use(express.favicon()); //app.use(express.compress()); app.use("/static", express.static(__dirname + '/static/')); app.use(express.cookieParser()); app.use(express.bodyParser()); app.use(express.session({ secret: cookieSecret, // store: new RedisStore(redisOptions) })); app.use(auth({ strategies: auth.Facebook({ appId : process.env.FACEBOOK_APP_ID || 0, appSecret: process.env.FACEBOOK_SECRET || "abcd1234", scope: "user_photos,manage_pages", // callback: process.env.FACEBOOK_CALLBACK || "http://photoflux.tarnet.ch/imback"}), // callback doit être ça, car hard-codé dans la strategie facebook // TODO: réécrire la strategie, pour être un peu plus modulable. callback: process.env.FACEBOOK_CALLBACK || "http://photoflux.tarnet.ch/auth/facebook_callback"}), trace: true})); app.use(app.router); /////////////////////////////////////////////////////// // Routes app.get("/", render("index.mustache", {title: "PhotoFlux | Page d'accueil"})); app.get("/letsgo", function(req, res) { res.render("letsgo.mustache", defaultData(req)); }); app.get("/loginWithFacebook", fbConnected, loginWithFacebook); app.get("/albumsSelection", fbConnected, albumsSelectionGet); app.get("/albumsSelection/:pid", fbConnected, albumsSelectionGet); app.post("/albumsSelection", fbConnected, albumsSelectionPost); app.post("/albumsSelection/:pid", fbConnected, albumsSelectionPost);
server.use(form()); server.use(express.cookieParser()); server.use(express.session({ secret: 'secret', store: new RedisStore(), cookie: {httpOnly: false} })); server.use(auth([ auth.Twitter({ consumerKey: config.TWITTER_KEY, consumerSecret: config.TWITTER_SECRET }), auth.Facebook({ appId: config.FACEBOOK_ID, appSecret: config.FACEBOOK_SECRET, callback: config.MAIN_URL + '/auth/facebook', scope: 'email' }), auth.Yahoo({ consumerKey: config.YAHOO_KEY, consumerSecret: config.YAHOO_SECRET, callback: config.MAIN_URL + '/auth/yahoo' }), auth.Google({ consumerKey: config.GOOGLE_KEY, consumerSecret: config.GOOGLE_SECRET, callback: config.MAIN_URL + '/auth/google', scope: "" }), formStrategy() ]));
else uid= det.user.id; sql = 'update usersocial set user_level = ' + numlesson + ' where ext_id = ' + sqlconn.escape(uid) ; sqlconn.query(sql); sqlconn.end(); //res.end(sql); } res.end(''); }); app.get(/.*/, function(req, res, params) { redirect(req, res, "/"); }); } var app = connect.createServer( connect.staticCache() , connect.static(__dirname + '/public', { maxAge: 2419200000}) , connect.cookieParser() , connect.session({secret: 'ajiozkaEsUnNombreMagico', store: new connect.session.MemoryStore({ reapInterval: -1 }) }) , auth( { strategies: [ auth.Facebook({appId : fbId, appSecret: fbSecret, scope: "", callback: fbCallbackAddress}) , auth.Twitter({consumerKey: twitterConsumerKey, consumerSecret: twitterConsumerSecret, callback: twitterCallbackAddress}) , auth.Google2({appId : google2Id, appSecret: google2Secret, callback: google2CallbackAddress})] , trace: true , firstLoginHandler: firstLoginHandler } ) , smalltalk_tutorial_middleware() , connect.router(routes) ).listen(process.env.PORT); //JUAS