<commit_before>var express = require('express');
var router = express.Router();
var request = require('request');
var Todo = require('../models/todo');
var validateTokenUrl = 'http://accounts.productiv.me/api/token/validate';

function auth(req, res, next) {
  var uid = req.cookies['productivUid'];
  var token = req.cookies['productivToken'];
  console.log('uid: ', uid);
  console.log('token: ', token);
  if(!(uid && token)) res.redirect('/login');

  request.post(validateTokenUrl, {
    uid: uid,
    token: token
  }, function (err, res, body) {
    if(err || res.statusCode !== 200) res.send(err);
    else if(res.success) next();
    else {
      console.log(res.message);
      res.redirect('/login');
    }
  });
};

router.get('/', auth, function(req, res) {
  var uid = req.cookies.uid;
  console.log('uid: ', uid);
  Todo.find({ owner: uid }, function(err, todos) {
    if(err) res.send(error);<commit_msg>cookies work!<commit_after>var express = require('express');
var router = express.Router();
var request = require('request');
var Todo = require('../models/todo');
var validateTokenUrl = 'http://accounts.productiv.me/api/token/validate';

function auth(req, res, next) {
  var uid = req.cookies['productivUid'];
  var token = req.cookies['productivToken'];
  console.log('uid: ', uid);
  console.log('token: ', token);
  if(!(uid && token)) res.redirect('/login');

  request.post({
    url: validateTokenUrl,
    body: {
      uid: uid,
      token: token
    },
    json: true
  }, function (err, _res, body) {
    console.log('err: ', err);
    console.log('_res: ', _res);
    console.log('body: ', body);
    if(err || _res.statusCode !== 200) res.send(err);
    else if(body.success) next();
    else {
      console.log('message: ', body.message);
      res.redirect('/login');
    }
  });
};

router.get('/', auth, function(req, res) {
  var uid = req.cookies.uid;
  console.log('uid: ', uid);
  Todo.find({ owner: uid }, function(err, todos) {
    if(err) res.send(error);
{'fraction_non_alphanumeric': 0.1984007996001999, 'fraction_numerical': 0.0029985007496251873, 'mean_word_length': 3.634259259259259, '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': '7009029', 'n_tokens_mistral': 684, 'n_tokens_neox': 675, 'n_words': 146}