<commit_before>var async     = require('async')
var op        = require('object-path')
var random    = require('randomstring')
var rethinkdb = require('rethinkdb')



// Create user session
exports.sessionStart = function(params, callback) {
    if(!params.user) { return callback(new Error('No user')) }

    var session = {
        created: new Date(),
        key: random.generate(64),
        user: {
            id: op.get(params, 'user.id'),
            provider: op.get(params, 'user.provider'),
            name: op.get(params, 'user.name'),
            email: op.get(params, 'user.email'),
            picture: op.get(params, 'user.picture')
        },
        ip: op.get(params, 'request.ip'),
        browser: op.get(params, 'request.headers.user-agent')
    }
    if(op.has(params, 'request.cookies.redirect')) { session.redirect = op.get(params, 'request.cookies.redirect') }

    async.waterfall([
        function(callback) {
            rethinkdb.connect({ host: APP_RETHINKDB_HOST }, function(err, conn) {
                if(err) { return callback(err) }

                var connection = conn

                async.waterfall([
                    function(callback) {
                        rethinkdb.dbList().run(connection, callback)
                    },
                    function(dbList, callback) {
                        if(dbList.indexOf('entu') > -1) {
                            connection.use('entu')
                            callback()<commit_msg>Set only user parameters what exists<commit_after>var async     = require('async')
var op        = require('object-path')
var random    = require('randomstring')
var rethinkdb = require('rethinkdb')



// Create user session
exports.sessionStart = function(params, callback) {
    if(!params.user) { return callback(new Error('No user')) }

    var session = {
        created: new Date(),
        key: random.generate(64),
    }

    if(op.get(params, 'user.id')) { op.set(session, 'user.id', op.get(params, 'user.id')) }
    if(op.get(params, 'user.provider')) { op.set(session, 'user.provider', op.get(params, 'user.provider')) }
    if(op.get(params, 'user.name')) { op.set(session, 'user.name', op.get(params, 'user.name')) }
    if(op.get(params, 'user.email')) { op.set(session, 'user.email', op.get(params, 'user.email')) }
    if(op.get(params, 'user.picture')) { op.set(session, 'user.picture', op.get(params, 'user.picture')) }
    if(op.get(params, 'request.ip')) { op.set(session, 'ip', op.get(params, 'request.ip')) }
    if(op.get(params, 'request.headers.user-agent')) { op.set(session, 'browser', op.get(params, 'request.headers.user-agent')) }
    if(op.get(params, 'request.cookies.redirect')) { op.set(session, 'redirect', op.get(params, 'request.cookies.redirect')) }

    async.waterfall([
        function(callback) {
            rethinkdb.connect({ host: APP_RETHINKDB_HOST }, function(err, conn) {
                if(err) { return callback(err) }

                var connection = conn

                async.waterfall([
                    function(callback) {
                        rethinkdb.dbList().run(connection, callback)
                    },
                    function(dbList, callback) {
                        if(dbList.indexOf('entu') > -1) {
                            connection.use('entu')
                            callback()
{'fraction_non_alphanumeric': 0.15764425936942297, 'fraction_numerical': 0.001784651992861392, 'mean_word_length': 2.1937321937321936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1016393', 'n_tokens_mistral': 1006, 'n_tokens_neox': 972, 'n_words': 185}