<commit_before>/**
 * Created by jakeforaker on 11/19/15.
 */


var SlackStrategy = require('passport-slack').Strategy;
var inspect = require('eyes').inspector();

var User = require('./models/user');
var configAuth = require('./auth');

module.exports = function (app, passport) {

    // seralize and deseralize user
    passport.serializeUser(function (user, done) {
        done(null, user._id);
    });
    passport.deserializeUser(function (id, done) {
        User.findById(id, function (err, user) {
            if (!err) done(null, user);
            else done(err, null);
        })
    });

    passport.use(new SlackStrategy({
            clientID: configAuth.slackAuth.clientID,
            clientSecret: configAuth.slackAuth.clientSecret,
            callbackURL: configAuth.slackAuth.callbackURL,
            scope: 'identify,read,client',
            passReqToCallback: true
        },
        function (req, accessToken, refreshToken, obj, profile, done) {

            process.nextTick(function () {

                if (!req.user) {

                    User.findOne({'slack.SlackId': profile.id}, function (err, user) {

                        if (err) return done(err);

                        if (user) {

                            // if there is a user id already but no token (user was linked at one point and then removed)
                            if (!user.slack.token) {
                                user.slack.token = accessToken;
                                user.slack.name = profile.displayName;
                                user.slack.email = profile._json.info.user.profile.email;
<commit_msg>update oath scopes<commit_after>/**
 * Created by jakeforaker on 11/19/15.
 */


var SlackStrategy = require('passport-slack').Strategy;
var inspect = require('eyes').inspector();

var User = require('./models/user');
var configAuth = require('./auth');

module.exports = function (app, passport) {

    // seralize and deseralize user
    passport.serializeUser(function (user, done) {
        done(null, user._id);
    });
    passport.deserializeUser(function (id, done) {
        User.findById(id, function (err, user) {
            if (!err) done(null, user);
            else done(err, null);
        })
    });

    passport.use(new SlackStrategy({
            clientID: configAuth.slackAuth.clientID,
            clientSecret: configAuth.slackAuth.clientSecret,
            callbackURL: configAuth.slackAuth.callbackURL,
            scope: 'channels:history, channels:read, emoji:read, files:read, groups:history, groups:read, ' +
                    'reactions:read, search:read, team:read, usergroups:read, users:read, identify',
            passReqToCallback: true
        },
        function (req, accessToken, refreshToken, obj, profile, done) {

            process.nextTick(function () {

                if (!req.user) {

                    User.findOne({'slack.SlackId': profile.id}, function (err, user) {

                        if (err) return done(err);

                        if (user) {

                            // if there is a user id already but no token (user was linked at one point and then removed)
                            if (!user.slack.token) {
                                user.slack.token = accessToken;
                                user.slack.name = profile.displayName;
                                user.slack.email = profile._json.info.user.profile.email;

{'fraction_non_alphanumeric': 0.1165750650853341, 'fraction_numerical': 0.0034712178189181373, 'mean_word_length': 1.84375, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3781559', 'n_tokens_mistral': 969, 'n_tokens_neox': 924, 'n_words': 223}