<commit_before>/**
 * Zizanie
 * Copyright (C) 2011 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var spore = require('spore')
  , express = require('express')
  , crypto = require('crypto')
;

var sign = require('./sign');
/**
 * Zizanie Controller
 * Wrap express for a more traditionnal way with controller class
 *
 * Params:
 *  - app: express application
 *  - config: zizanie config
 *  - db: mongoose instance (see models/index.js)
 */
function ZizanieController(app, config, db) {
    this.config   = config;
    this.db       = db;
    this.app      = app;

    // TODO: should be moved in a custom location
    this.facebook = require('facebook-js')(config.facebook.appId, config.facebook.secret);

    // all routes are here
    this.routes = [
        {verb: 'get',  path: '/', fun: 'index'},
        {verb: 'post', path: '/user/sign_in', fun: 'sign_in'},
        {verb: 'get',  path: '/user/account', fun: 'account'},
        {verb: 'post', path: '/user/account/facebook', fun: 'update_account_facebook'},
        {verb: 'post', path: '/user/account/password', fun: 'update_account_password'},
        {verb: 'get', path: '/user/lost-password', fun: 'lost_password'},
        {verb: 'post', path: '/user/lost-password', fun: 'lost_password_send_token'},
        {verb: 'get', path: '/user/lost-password/:token', fun: 'lost_password_with_token'},
        {verb: 'post', path: '/user/logout', fun: 'logout'},
        {verb: 'get',  path: '/facebook/canvas', fun: 'facebook_canvas'},
        {verb: 'get',  path: '/facebook/oauth_redirect', fun: 'facebook_oauth_redirect'}
    ];
}
ZizanieController.prototype = {
    _config: function() {
        var app = this.app;

        app.set('views', __dirname + '/templates');
        app.set('view engine', 'jade');

        app.use(express.cookieDecoder());
        app.use(express.bodyDecoder());

        var public_dir = __dirname + '/../../public';
        app.use(express.compiler({ src: public_dir, enable: ['less'] }));
        app.use(express.staticProvider(public_dir));

        app.use(this._configureFacebook());

        app.configure('development', function(){
            app.use(express.session()); // memory store
            app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
        });

        app.configure('production', function(){
            app.use(express.session());
            app.use(express.errorHandler());
        });

        app.configure('test', function() {
            // special memory store for testing, doesn't reap old session
            app.use(express.session({store: new express.session.MemoryStore({reapInterval: -1})}));
            app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
        });

        app.use(this._session());
        app.use(this._layout());
    },

    /**
     * Configure facebook
     * should be disabled, facebook is bad
     */
    _configureFacebook: function() {
        var config = this.config;
        return require('facebook').Facebook({
            apiKey    : config.facebook.appId,
            apiSecret : config.facebook.secret
        });
    },<commit_msg>Configure session middleware with secret.<commit_after>/**
 * Zizanie
 * Copyright (C) 2011 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var spore = require('spore')
  , express = require('express')
  , crypto = require('crypto')
;

var sign = require('./sign');
/**
 * Zizanie Controller
 * Wrap express for a more traditionnal way with controller class
 *
 * Params:
 *  - app: express application
 *  - config: zizanie config
 *  - db: mongoose instance (see models/index.js)
 */
function ZizanieController(app, config, db) {
    this.config   = config;
    this.db       = db;
    this.app      = app;

    // TODO: should be moved in a custom location
    this.facebook = require('facebook-js')(config.facebook.appId, config.facebook.secret);

    // all routes are here
    this.routes = [
        {verb: 'get',  path: '/', fun: 'index'},
        {verb: 'post', path: '/user/sign_in', fun: 'sign_in'},
        {verb: 'get',  path: '/user/account', fun: 'account'},
        {verb: 'post', path: '/user/account/facebook', fun: 'update_account_facebook'},
        {verb: 'post', path: '/user/account/password', fun: 'update_account_password'},
        {verb: 'get',  path: '/user/lost-password', fun: 'lost_password'},
        {verb: 'post', path: '/user/lost-password', fun: 'lost_password_send_token'},
        {verb: 'get',  path: '/user/lost-password/:token', fun: '<PASSWORD>with_token'},
        {verb: 'post', path: '/user/logout', fun: 'logout'},
        {verb: 'get',  path: '/facebook/canvas', fun: 'facebook_canvas'},
        {verb: 'get',  path: '/facebook/oauth_redirect', fun: 'facebook_oauth_redirect'}
    ];
}
ZizanieController.prototype = {
    _config: function() {
        var app = this.app;
        var config = this.config;

        app.set('views', __dirname + '/templates');
        app.set('view engine', 'jade');

        app.use(express.cookieDecoder());
        app.use(express.bodyDecoder());

        var public_dir = __dirname + '/../../public';
        app.use(express.compiler({ src: public_dir, enable: ['less'] }));
        app.use(express.staticProvider(public_dir));

        app.use(this._configureFacebook());

        app.configure('development', function(){
            app.use(express.session({secret: config.secret})); // memory store
            app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
        });

        app.configure('production', function(){
            app.use(express.session({secret: config.secret}));
            app.use(express.errorHandler());
        });

        app.configure('test', function() {
            // special memory store for testing, doesn't reap old session
            app.use(express.session({secret: config.secret, store: new express.session.MemoryStore({reapInterval: -1})}));
            app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
        });

        app.use(this._session());
        app.use(this._layout());
    },

    /**
     * Configure facebook
     * should be disabled, facebook is bad
     */
    _configureFacebook: function() {
        var config = this.config;
        return require('facebook').Facebook({
            apiKey    : config.facebook.appId,
            apiSecret : config.facebook.secret
        });
    },
{'fraction_non_alphanumeric': 0.1471619690868944, 'fraction_numerical': 0.0015586439797376282, 'mean_word_length': 2.8194444444444446, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1266905', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2162, 'n_words': 637}