<commit_before>var users = require('./users_data.js');

exports.checkUserPwd = (usname, password, callback) => {
  var user = users.filter((u) => {
    return u.usname == usname && u.pwd == password;
  });

  if (user != null && user.length == 1) {
    callback(null, {
      id: user[0].id,
      nickname: user[0].nickname,
      role: user[0].role,
      lastip: user[0].lastip,
      regtime: user[0].regtime,
      lasttime: user[0].lasttime,
      status: user[0].status,
      usname: user[0].usname
    });
  } else {
    callback({error: `${usname} not valid`});
  }
}

exports.single_user = (id, callback) => {
  var user = users.filter((u) => { return u.id == id; });
  if (user != null && user.length > 0) callback(null, {
    id: user[0].id,
    nickname: user[0].nickname,
    role: user[0].role,
    lastip: user[0].lastip,
    regtime: user[0].regtime,
    lasttime: user[0].lasttime,
    status: user[0].status,
    usname: user[0].usname
  });
  else callback({error: `user id ${id} not found!`});
};

exports.all_users = (pageIndex, pageCount, role, callback) => {

  var matchedUsers = null;
  if (role == 0) {
    matchedUsers = users;
  } else {
    matchedUsers = users.filter((user) => {
      return user.role == role;
    });
  }

  var sliceStart = (pageIndex - 1) * pageCount;
  var sliceEnd = sliceStart + pageCount;

  var data = {
    total: matchedUsers.length,
    pageIndex: pageIndex,
    pageCount: pageCount
  };

  var usersSliced = matchedUsers.slice(sliceStart, sliceEnd);

  var u = [];
  usersSliced.forEach((user) => {
    u.push({
      id: user.id,
      nickname: user.nickname,
      role: user.role,
      lastip: user.lastip,
      regtime: user.regtime,
      lasttime: user.lasttime,
      status: user.status,
      usname: user.usname
    });
  });

  data.users = u;

  callback(null, data);
};

function addUser(user, callback)
{
  if (users.length == 0) user.id = 1;
  else user.id = users[users.length - 1].id + 1;

  //var d = new Date();
  user.regtime = "";//d.toLocaleString();
  user.lasttime = "";//d.toLocaleString();
  user.lastip = "";
  user.status = 0;
  users.push(user);

  callback(null, {
    id: user.id,
    nickname: user.nickname,
    role: user.role,
    regtime: user.regtime,
    status: user.status,
    usname: user.usname,
    lasttime: user.lasttime,
    lastip: user.lastip
  });
}
<commit_msg>Added regtime value in user object.<commit_after>var users = require('./users_data.js');

exports.checkUserPwd = (usname, password, callback) => {
  var user = users.filter((u) => {
    return u.usname == usname && u.pwd == password;
  });

  if (user != null && user.length == 1) {
    callback(null, {
      id: user[0].id,
      nickname: user[0].nickname,
      role: user[0].role,
      lastip: user[0].lastip,
      regtime: user[0].regtime,
      lasttime: user[0].lasttime,
      status: user[0].status,
      usname: user[0].usname
    });
  } else {
    callback({error: `${usname} not valid`});
  }
}

exports.single_user = (id, callback) => {
  var user = users.filter((u) => { return u.id == id; });
  if (user != null && user.length > 0) callback(null, {
    id: user[0].id,
    nickname: user[0].nickname,
    role: user[0].role,
    lastip: user[0].lastip,
    regtime: user[0].regtime,
    lasttime: user[0].lasttime,
    status: user[0].status,
    usname: user[0].usname
  });
  else callback({error: `user id ${id} not found!`});
};

exports.all_users = (pageIndex, pageCount, role, callback) => {

  var matchedUsers = null;
  if (role == 0) {
    matchedUsers = users;
  } else {
    matchedUsers = users.filter((user) => {
      return user.role == role;
    });
  }

  var sliceStart = (pageIndex - 1) * pageCount;
  var sliceEnd = sliceStart + pageCount;

  var data = {
    total: matchedUsers.length,
    pageIndex: pageIndex,
    pageCount: pageCount
  };

  var usersSliced = matchedUsers.slice(sliceStart, sliceEnd);

  var u = [];
  usersSliced.forEach((user) => {
    u.push({
      id: user.id,
      nickname: user.nickname,
      role: user.role,
      lastip: user.lastip,
      regtime: user.regtime,
      lasttime: user.lasttime,
      status: user.status,
      usname: user.usname
    });
  });

  data.users = u;

  callback(null, data);
};

function addUser(user, callback)
{
  if (users.length == 0) user.id = 1;
  else user.id = users[users.length - 1].id + 1;

  var d = new Date();
  user.regtime = d.toLocaleString();
  user.lasttime = "";//d.toLocaleString();
  user.lastip = "";
  user.status = 0;
  users.push(user);

  callback(null, {
    id: user.id,
    nickname: user.nickname,
    role: user.role,
    regtime: user.regtime,
    status: user.status,
    usname: user.usname,
    lasttime: user.lasttime,
    lastip: user.lastip
  });
}

{'fraction_non_alphanumeric': 0.16893732970027248, 'fraction_numerical': 0.010479983232026828, 'mean_word_length': 2.7545239968528716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5589912', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1711, 'n_words': 377}