<commit_before>Router.configure({
    layoutTemplate: 'main'
});
Router.route('/', {
    template: 'home'
});
Router.route('/create', {
    template: 'create'
});
Router.route('/join', {
    template: 'join'
});
Router.route('/login', {
    template: 'login'
});
Router.route('/dashboard', {
    template: 'dashboard'
});
Router.route('/pregame', {
    template: 'pregame'
});
Router.route('/start', {
    template: 'start'
});
if (Meteor.isClient) {
  Template.join.helpers({
    bad_game_id: function() {
      return Session.get("bad_game_id");
    }
  });

  Template.join.events({
    "submit form": function(event) {
      event.preventDefault();
      var game_id = event.target.name.value;
      var game = Games.findOne({
        "id": game_id
      });
      console.log("Joining " + game_id);
      if (game) {
        Session.set("bad_game_id", undefined);
        Session.set("game_id", game_id);
      } else {
        Session.set("bad_game_id", game_id);
      }
    }
  });

  Template.pregame.helpers({
      manager: function() {
        var user = Users.findOne({id: Session.get("currentUser")});
        if (user == undefined) return false;
        var game = Games.findOne({id: user.gameId});
        return (game.managerId == user.id);
      }
  });


  Template.dashboard.events({
      "click button": function() {
        console.log("here we are");
        // get user's victim and send it to the killer
        var userId = Meteor.userId();
        var userInfo = Posts.findOne({
          id: userId
        });
        var killerId = userInfo.killerId;
        var killerInfo = Post.findOne({
          id: killerId
        });
        console.log("email is trying to send");
        Email.send({
          "from": "<EMAIL>",
          "to": [
            killerInfo.email
           ],
          "subject": "your target is",
          "text": userInfo.current_victim,
          "html": '<h1 style="color: blue; background: red">MORE EXCITING</h1><br><span style="font-size:6pt">I apologize for that.</style>'
        });
      }
  });
  
  Template.login.events({
    "submit form": function(event) {
      event.preventDefault();
      var user = Users.findOne({
        "id": event.target.username.value
      });
      if (user) {
        Session.set("currentUser", user)
        Router.go('dashboard');
      } else {
        alert("User does not exist");
      }
    }
  });

  Template.home.helpers({
    currentUser: function() {
      return Session.get("currentUser");
    }
  })
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    process.env.MAIL_URL = "smtp://outgoing.mit.edu:25/"

    // DONT DO IT!
    if (false) {
      console.log("sending email");
      Email.send({
        "from": "<EMAIL>",
        "to": [
          "<EMAIL>"
        ],
        "subject": "now it sends emails",
        "text": "exciting",
        "html": '<h1 style="color: blue; background: red">MORE EXCITING</h1><br><span style="font-size:6pt">I apologize for that.</style>'
      });
      console.log("email sent");
    }
  });
}


/*
Database Collections: Users and Games
Maybe we should sequester this somewhere else
*/
Games = new Mongo.Collection("games");
Users = new Mongo.Collection("users");

function load_sample_data() {
  //sample user
    Users.insert({
    id: "Anna",
    email: "<EMAIL>",
    killerId: "Andres",
    gameID: "Sample",
    status: "Dead",
    current_victim: "Jess",
    victim_list: []
  });
  Users.insert({
    id: "Jess",
    email: "<EMAIL>",
    killerId: "Anna",
    gameID: "Sample",
    status: "Dead",
    current_victim: "Andres",
    victim_list: []
  });
  Users.insert({
    id: "Andres",
    email: "<EMAIL>",
    killerId: "Jess",
    gameID: "Sample",
    status: "Dead",
    current_victim: "Anna",
    victim_list: []
  });

  //sample game
  Games.insert({
    id: "Sample",
    mailing_list: "<EMAIL>",
    manager: "Jess"
  });
}
<commit_msg>add create logic<commit_after>Router.configure({
    layoutTemplate: 'main'
});
Router.route('/', {
    template: 'home'
});
Router.route('/create', {
    template: 'create'
});
Router.route('/join', {
    template: 'join'
});
Router.route('/login', {
    template: 'login'
});
Router.route('/dashboard', {
    template: 'dashboard'
});
Router.route('/pregame', {
    template: 'pregame'
});
Router.route('/start', {
    template: 'start'
});
if (Meteor.isClient) {
  Template.create.events({
    "submit form": function(event) {
      event.preventDefault();
      var game_id = event.target.name.value;
      var mailing_list = event.target.list.value;
      var game = Games.findOne({
        "id": game_id
      });

      if (game) {
        console.log("That already exists yo");
        return;
      }

      if (!game_id) {
        console.log("For the love of god give a name.");
        return;
      }

      if (!mailing_list) {
        console.log("provide a mailing list.")
        return;
      }

      Games.insert({
        id: game_id,
        mailing_list: mailing_list,
        manager_id: "Jess" // TODO, no fair
      });
      Session.set("game_id", game_id);
      console.log("Ok, diddly done.");
      Router.go("/");
    }
  });

  Template.join.helpers({
    bad_game_id: function() {
      return Session.get("bad_game_id");
    }
  });

  Template.join.events({
    "submit form": function(event) {
      event.preventDefault();
      var game_id = event.target.name.value;
      var game = Games.findOne({
        "id": game_id
      });
      console.log("Joining " + game_id);
      if (game) {
        Session.set("bad_game_id", undefined);
        Session.set("game_id", game_id);
        Router.go("/");
      } else {
        Session.set("bad_game_id", game_id);
      }
    }
  });

  Template.pregame.helpers({
      manager: function() {
        var user = Users.findOne({id: Session.get("currentUser")});
        if (user == undefined) return false;
        var game = Games.findOne({id: user.gameId});
        return (game.managerId == user.id);
      }
  });


  Template.dashboard.events({
      "click button": function() {
        console.log("here we are");
        // get user's victim and send it to the killer
        var userId = Meteor.userId();
        var userInfo = Posts.findOne({
          id: userId
        });
        var killerId = userInfo.killerId;
        var killerInfo = Post.findOne({
          id: killerId
        });
        console.log("email is trying to send");
        Email.send({
          "from": "<EMAIL>",
          "to": [
            killerInfo.email
           ],
          "subject": "your target is",
          "text": userInfo.current_victim,
          "html": '<h1 style="color: blue; background: red">MORE EXCITING</h1><br><span style="font-size:6pt">I apologize for that.</style>'
        });
      }
  });
  
  Template.login.events({
    "submit form": function(event) {
      event.preventDefault();
      var user = Users.findOne({
        "id": event.target.username.value
      });
      if (user) {
        Session.set("currentUser", user)
        Router.go('dashboard');
      } else {
        alert("User does not exist");
      }
    }
  });

  Template.home.helpers({
    currentUser: function() {
      return Session.get("currentUser");
    }
  })
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    process.env.MAIL_URL = "smtp://outgoing.mit.edu:25/"

    // DONT DO IT!
    if (false) {
      console.log("sending email");
      Email.send({
        "from": "<EMAIL>",
        "to": [
          "<EMAIL>"
        ],
        "subject": "now it sends emails",
        "text": "exciting",
        "html": '<h1 style="color: blue; background: red">MORE EXCITING</h1><br><span style="font-size:6pt">I apologize for that.</style>'
      });
      console.log("email sent");
    }
  });
}


/*
Database Collections: Users and Games
Maybe we should sequester this somewhere else
*/
Games = new Mongo.Collection("games");
Users = new Mongo.Collection("users");

function load_sample_data() {
  //sample user
    Users.insert({
    id: "Anna",
    email: "<EMAIL>",
    killerId: "Andres",
    gameID: "Sample",
    status: "Dead",
    current_victim: "Jess",
    victim_list: []
  });
  Users.insert({
    id: "Jess",
    email: "<EMAIL>",
    killerId: "Anna",
    gameID: "Sample",
    status: "Dead",
    current_victim: "Andres",
    victim_list: []
  });
  Users.insert({
    id: "Andres",
    email: "<EMAIL>",
    killerId: "Jess",
    gameID: "Sample",
    status: "Dead",
    current_victim: "Anna",
    victim_list: []
  });

  //sample game
  Games.insert({
    id: "Sample",
    mailing_list: "<EMAIL>",
    manager_id: "Jess"
  });
}

{'fraction_non_alphanumeric': 0.17125417482436947, 'fraction_numerical': 0.0018426811010019578, 'mean_word_length': 2.2794561933534743, 'pattern_counts': {'":': 32, '<': 37, '<?xml version=': 0, '>': 37, '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': '4315316', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2801, 'n_words': 596}