<commit_before>
var Crypto = require('crypto');
var Commands = require('commands');
var hashSalt = Commands.get('salt', process.env.sessionKey);

var properties = require('properties-reader')('src/properties/auth.properties');
var express = require('express');
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var database = require('../database');

function User (profile) {
    console.log('User', require('util').inspect(profile));

    var email = (Array.isArray(profile.emails) ? profile.emails[0] : profile.emails || profile.email) || null;
    var id = email || profile.id;

    this.id = typeof profile === "string" ? profile : Crypto.createHash('sha1')
        .update(id + hashSalt, 'utf8')
        .digest('base64');
}

// converts the complete user to just the detail that will be saved to the user session
passport.serializeUser(function(user, done) {
    done(null, user.id);
});

// converts the session stored value back into a complete user object
passport.deserializeUser(function(id, done) {
    console.log('deserializeUser', id);
    done(null, new User(id));
});

// Facebook strategy<commit_msg>Flatten value objects in the email address for user creation Remove logging<commit_after>
var Crypto = require('crypto');
var Commands = require('commands');
var hashSalt = Commands.get('salt', process.env.sessionKey);

var properties = require('properties-reader')('src/properties/auth.properties');
var express = require('express');
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var database = require('../database');

function User (profile) {
    var email = (Array.isArray(profile.emails) ? profile.emails[0] : profile.emails || profile.email) || null;
    var id = email || profile.id;

    if (typeof id === "object" && id && id.value) {
        id = id.value;
    }

    this.id = typeof profile === "string" ? profile : Crypto.createHash('sha1')
        .update(id + hashSalt, 'utf8')
        .digest('base64');
}

// converts the complete user to just the detail that will be saved to the user session
passport.serializeUser(function(user, done) {
    done(null, user.id);
});

// converts the session stored value back into a complete user object
passport.deserializeUser(function(id, done) {
    done(null, new User(id));
});

// Facebook strategy
{'fraction_non_alphanumeric': 0.14773629864972201, 'fraction_numerical': 0.004765687053216839, 'mean_word_length': 4.560706401766004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3679954', 'n_tokens_mistral': 728, 'n_tokens_neox': 712, 'n_words': 204}