<commit_before>import bcrypt from 'bcryptjs';

export default function() {
  let {
    nq,
    app,
    db,
    config,
    reject,
    makeToken,
    decodeToken,
    collection,
    authToken,
  } = this;

  function login(ns, name, pwd, cb) {
    if (!ns ||
        !name ||
        !pwd ||
        typeof name !== 'string' ||
        typeof pwd !== 'string') return cb(null);

    db.db(ns).collection('db.users').findOne({ name: name }, (err, r) => {
      if (err ||
          !r ||
          !r.enabled ||
          !r.pwd ||
          !bcrypt.compareSync(pwd, r.pwd)) {
        return cb(null);
      }
      let profile = {
        name: name,
        pwd: <PASSWORD>,
        ns: ns,
        role: r.role || null
      };
      cb({ token: makeToken(profile) });
    });
  }

  nq.on('login', null, (q, req, res) => {
    login(q.name, q.params.name, q.params.pwd, r => {
      if (!r) return reject(res);
      res.json(q.response(r));
    });
  });

  nq.on('refresh', '', (q, req, res) => {
    let user = decodeToken((authToken(req)));
    if (!user) return reject(res);
    login(user.ns, user.name, user.pwd, r => {
      res.json(q.response(r));
    });
  });

  nq.on('key', '', (q, req, res) => {
    res.json(q.response({
      key: config.keys.public
    }));
  });
}<commit_msg>remove key method<commit_after>import bcrypt from 'bcryptjs';

export default function() {
  let {
    nq,
    app,
    db,
    config,
    reject,
    makeToken,
    decodeToken,
    collection,
    authToken,
  } = this;

  function login(ns, name, pwd, cb) {
    if (!ns ||
        !name ||
        !pwd ||
        typeof name !== 'string' ||
        typeof pwd !== 'string') return cb(null);

    db.db(ns).collection('db.users').findOne({ name: name }, (err, r) => {
      if (err ||
          !r ||
          !r.enabled ||
          !r.pwd ||
          !bcrypt.compareSync(pwd, r.pwd)) {
        return cb(null);
      }
      let profile = {
        name: name,
        pwd: <PASSWORD>,
        ns: ns,
        role: r.role || null
      };
      cb({ token: makeToken(profile) });
    });
  }

  nq.on('login', null, (q, req, res) => {
    login(q.name, q.params.name, q.params.pwd, r => {
      if (!r) return reject(res);
      res.json(q.response(r));
    });
  });

  nq.on('refresh', '', (q, req, res) => {
    let user = decodeToken((authToken(req)));
    if (!user) return reject(res);
    login(user.ns, user.name, user.pwd, r => {
      res.json(q.response(r));
    });
  });
}
{'fraction_non_alphanumeric': 0.19326383319967924, 'fraction_numerical': 0.0, 'mean_word_length': 1.9045401629802095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '318604', 'n_tokens_mistral': 904, 'n_tokens_neox': 894, 'n_words': 195}