<commit_before>'use strict';

var routes = require('express').Router();
var cookieParser = require('cookie-parser');

var cookieOptions = {
  httpOnly: true,
  domain: '.emunova.net'
};

routes.get('/me', cookieParser(null, cookieOptions), function(req, res){
  if (!req.cookies.member_id) {
    return res.status(404).send({});
  }

  res.json({
    user: {
      id: req.cookies.member_id
    }
  });
});

module.exports = routes;<commit_msg>Query and exports user data like SEO Name, profile URL and user name.<commit_after>'use strict';

var cookieParser = require('cookie-parser');

var cookieOptions = {
  httpOnly: true,
  domain: '.emunova.net'
};

module.exports = function(app){
  var routes = require('express').Router();

  routes.get('/me', cookieParser(null, cookieOptions), function(req, res){
    if (!req.cookies.member_id) {
      return res.status(404).send({});
    }

    app.locals.db
      .select('name', 'members_seo_name')
      .where('member_id', req.cookies.member_id)
      .from('ibf_members')
      .limit(1)
      .first()
      .then(successResponse, errorResponse);

    //
    function successResponse(row){
      res.setHeader('Cache-Control', 'private');
      res.setHeader('Expires', new Date(Date.now() + 3600000));

      res.json({
        user: {
          id: Number(req.cookies.member_id),
          name: row.name,
          slug: row.members_seo_name,
          profile_url: 'http://forums.emunova.net/user/' + req.cookies.member_id + '-' + row.members_seo_name + '/'
        }
      });
    }

    function errorResponse(err){
      console.error('Failed to fetch user informations.');
      console.error(err);

      res.status(400).json({});
    }
  });

  return routes;
};
{'fraction_non_alphanumeric': 0.16685979142526072, 'fraction_numerical': 0.009849362688296639, 'mean_word_length': 2.9884526558891453, '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': '1027951', 'n_tokens_mistral': 580, 'n_tokens_neox': 561, 'n_words': 106}