<commit_before>/**
 * GET /
 * Home page.
 */
var User = require('../models/User');
var nodemailer = require("nodemailer");
var secrets = require('../config/secrets.js');
var path = require('path');
var templatesDir = path.resolve('templates');
var emailTemplates = require('email-templates');


exports.index = function(req, res) {
  if(req.user)
    if(req.user.isNewUser) {
      req.flash('info', { msg: 'Please update your profile before proceeding' });
      res.redirect('/account');
    }
    else
      getUser(req, res);
  else
    res.redirect('/login');
};

exports.postRating = function(req, res) {
  var isApproved = req.body.isApproved;
  var userID = req.body.userID;

  console.log('vote is posted');
  console.log(req.body);

  console.log(req.user.id +  " is user id");
  console.log('isApproved:' + isApproved);

  User.findById(req.user.id, function(err, user) {
    if(isApproved === true || isApproved === "true") {
      console.log(err);
      console.log('is true');
      console.log('User is ' + user.profile.name.first)
      console.log('Accepted is ' + userID);
      user.profile.acceptedUsers.push(userID);
      user.save();
      User.findById(userID, function(err2, user2) {
      emailTemplates(templatesDir, function(err, template) {

  if (err) {
    console.log(err);
  } else {

    var transportBatch = nodemailer.createTransport("SMTP", {
    service: "Mandrill",
    auth: {
        user: secrets.mandrill.user,
        pass: secrets.mandrill.password
    }
});

    // users object
    var users = [
      {
        email: user.email,
        name: {
          first: user.profile.name.first,
          last: user.profile.name.last
        },
        matchName: user2.profile.name.first,
        matchPicture: user2.profile.picture,
        matchUniversity: user2.profile.university,
        matchEmail: user2.email
      },
      {
        email: user2.email,
        name: {
          first: user2.profile.name.first,
          last: user2.profile.name.last
        },
        matchName: user.profile.name.first,
        matchPicture: user.profile.picture,
        matchUniversity: user.profile.university,
        matchEmail: user.email
      }
    ];



    // Custom function for sending emails outside the loop
    //
    var Render = function(locals) {
      this.locals = locals;
      console.log*(locals);
      this.send = function(err, html, text) {
        if (err) {
          console.log(err);
        } else {
          transportBatch.sendMail({
            from: 'Snippet <<EMAIL>>',
            to: locals.email,
            reply_to: locals.matchEmail,
            subject: 'You Have a new Match on Snippet!',
            html: html,
            //generateTextFromHTML: true,
            text: text,
          }, function(err, responseStatus) {
            if (err) {
              console.log(err);
            } else {
              console.log(responseStatus.message);
            }
          });
        }
      };
      this.batch = function(batch) {
        batch(this.locals, templatesDir, this.send);
      };
    };

    // Load the template and send the emails
    template('snippet', true, function(err, batch) {
      for(var user in users) {
        var render = new Render(users[user]);
        render.batch(batch);
      }
    });




<commit_msg>Only matches get emailed now<commit_after>/**
 * GET /
 * Home page.
 */
var User = require('../models/User');
var nodemailer = require("nodemailer");
var secrets = require('../config/secrets.js');
var path = require('path');
var templatesDir = path.resolve('templates');
var emailTemplates = require('email-templates');


exports.index = function(req, res) {
  if(req.user)
    if(req.user.isNewUser) {
      req.flash('info', { msg: 'Please update your profile before proceeding' });
      res.redirect('/account');
    }
    else
      getUser(req, res);
  else
    res.redirect('/login');
};

exports.postRating = function(req, res) {
  var isApproved = req.body.isApproved;
  var userID = req.body.userID;

  console.log('vote is posted');
  console.log(req.body);

  console.log(req.user.id +  " is user id");
  console.log('isApproved:' + isApproved);

  User.findById(req.user.id, function(err, user) {
    if(isApproved === true || isApproved === "true") {
      console.log(err);
      console.log('is true');
      console.log('User is ' + user.profile.name.first)
      console.log('Accepted is ' + userID);
      user.profile.acceptedUsers.push(userID);
      user.save();
      User.findById(userID, function(err2, user2) {
        emailTemplates(templatesDir, function(err, template) {

        if (err2) {
          console.log(err);
        } else if(user2.profile.acceptedUsers.indexOf(req.user.id) != -1) {

          var transportBatch = nodemailer.createTransport("SMTP", {
            service: "Mandrill",
            auth: {
                user: secrets.mandrill.user,
                pass: <PASSWORD>
            }
          });

          // users object
          var users = [
            {
              email: user.email,
              name: {
                first: user.profile.name.first,
                last: user.profile.name.last
              },
              matchName: user2.profile.name.first,
              matchPicture: user2.profile.picture,
              matchUniversity: user2.profile.university,
              matchEmail: user2.email
            },
            {
              email: user2.email,
              name: {
                first: user2.profile.name.first,
                last: user2.profile.name.last
              },
              matchName: user.profile.name.first,
              matchPicture: user.profile.picture,
              matchUniversity: user.profile.university,
              matchEmail: user.email
            }
          ];



    // Custom function for sending emails outside the loop
    //
        var Render = function(locals) {
          this.locals = locals;
          console.log*(locals);
          this.send = function(err, html, text) {
            if (err) {
              console.log(err);
            } else {
              transportBatch.sendMail({
                from: 'Snippet <<EMAIL>>',
                to: locals.email,
                reply_to: locals.matchEmail,
                subject: 'You Have a new Match on Snippet!',
                html: html,
                //generateTextFromHTML: true,
                text: text,
              }, function(err, responseStatus) {
                if (err) {
                  console.log(err);
                } else {
                  console.log(responseStatus.message);
                }
              });
            }
          };
          this.batch = function(batch) {
            batch(this.locals, templatesDir, this.send);
          };
        };

        // Load the template and send the emails
        template('snippet', true, function(err, batch) {
          for(var user in users) {
            var render = new Render(users[user]);
            render.batch(batch);
          }
        });





{'fraction_non_alphanumeric': 0.13111048318734106, 'fraction_numerical': 0.00296693981350664, 'mean_word_length': 1.8158313444709626, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '6230994', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2024, 'n_words': 422}