<commit_before>/*
 * Stores session data in the database
 * Source; https://github.com/edy-b/SciFlowWriter/blob/develop/available_plugins/ep_sciflowwriter/db/DirtyStore.js
 * This is not used for authors that are created via the API at current
 *
 * RPB: this module was not migrated to Promises, because it is only used via
 *      express-session, which can't actually use promises anyway.
 */

var Store = require('ep_etherpad-lite/node_modules/express-session').Store,
  db = require('ep_etherpad-lite/node/db/DB').db,
  log4js = require('ep_etherpad-lite/node_modules/log4js'),
  messageLogger = log4js.getLogger("SessionStore");

var SessionStore = module.exports = function SessionStore() {};

SessionStore.prototype.__proto__ = Store.prototype;

SessionStore.prototype.get = function(sid, fn) {
  messageLogger.debug('GET ' + sid);

  var self = this;

  db.get("sessionstorage:" + sid, function(err, sess) {
    if (sess) {
      sess.cookie.expires = 'string' == typeof sess.cookie.expires ? new Date(sess.cookie.expires) : sess.cookie.expires;
      if (!sess.cookie.expires || new Date() < sess.cookie.expires) {
        fn(null, sess);
      } else {
        self.destroy(sid, fn);
      }
    } else {
      fn();
    }
  });
};

SessionStore.prototype.set = function(sid, sess, fn) {
  messageLogger.debug('SET ' + sid);

  db.set("sessionstorage:" + sid, sess);
  if (fn) {
    process.nextTick(fn);
  }
};

SessionStore.prototype.destroy = function(sid, fn) {
  messageLogger.debug('DESTROY ' + sid);<commit_msg>SessionStore: replace password with PASSWORD_HIDDEN when storing in db<commit_after>/*
 * Stores session data in the database
 * Source; https://github.com/edy-b/SciFlowWriter/blob/develop/available_plugins/ep_sciflowwriter/db/DirtyStore.js
 * This is not used for authors that are created via the API at current
 *
 * RPB: this module was not migrated to Promises, because it is only used via
 *      express-session, which can't actually use promises anyway.
 */

var Store = require('ep_etherpad-lite/node_modules/express-session').Store,
  db = require('ep_etherpad-lite/node/db/DB').db,
  log4js = require('ep_etherpad-lite/node_modules/log4js'),
  messageLogger = log4js.getLogger("SessionStore");

var SessionStore = module.exports = function SessionStore() {};

SessionStore.prototype.__proto__ = Store.prototype;

SessionStore.prototype.get = function(sid, fn) {
  messageLogger.debug('GET ' + sid);

  var self = this;

  db.get("sessionstorage:" + sid, function(err, sess) {
    if (sess) {
      sess.cookie.expires = 'string' == typeof sess.cookie.expires ? new Date(sess.cookie.expires) : sess.cookie.expires;
      if (!sess.cookie.expires || new Date() < sess.cookie.expires) {
        fn(null, sess);
      } else {
        self.destroy(sid, fn);
      }
    } else {
      fn();
    }
  });
};

SessionStore.prototype.set = function(sid, sess, fn) {
  messageLogger.debug('SET ' + sid);

  // don't store passwords in DB
  if (sess.user && sess.user.password) {
    sess.user.password = "<PASSWORD>";
  }

  db.set("sessionstorage:" + sid, sess);
  if (fn) {
    process.nextTick(fn);
  }
};

SessionStore.prototype.destroy = function(sid, fn) {
  messageLogger.debug('DESTROY ' + sid);
{'fraction_non_alphanumeric': 0.14073615836684195, 'fraction_numerical': 0.0018558614290133002, 'mean_word_length': 3.6599423631123917, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '2238931', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1037, 'n_words': 237}