<commit_before>'use strict'

var fs = require('fs')
var Path = require('path')
var Rand = require('crypto-rand')
var Crypto = require('crypto-js')
var Database = require(Path.join(__base, 'src/database/client.js'))
var DB = {
  user: new Database('user', __config.database.host, __config.database.port, __DBtoken),
  invitation: new Database('invitation', __config.database.host, __config.database.port, __DBtoken),
  token: new Database('token', __config.database.host, __config.database.port, __DBtoken)
}

var Log = require(Path.join(__base, 'src/worker/log.js'))
var LogWorker = new Log({
  module: 'Auth'
})

function Auth () {
  var self = this

  setInterval(self.cleanToken, 60000)
}

Auth.prototype.login = function (user, pass, ip, cb) {
  var self = this
  var login = function () {
    DB.user.find({
      user: user,
      password: <PASSWORD>
    }, function (err, res) {
      if (err) {
        LogWorker.error(err)
        cb(false)
      } else {
        if (res <= 0) {
          cb(false)
        } else {
          self.genUserToken(user, pass, function (token) {
            LogWorker.info(`${user} login from ${ip}.`)
            cb(token)
          })
        }
      }
    })
  }

  setTimeout(login)
}

Auth.prototype.logout = function (user, token, cb) {
  var self = this
  var logout = function () {
    DB.token.find({
      user: user,
      token: Crypto.SHA256(token).toString()
    }, function (err, res) {
      if (err) {
        LogWorker.error(err)
        cb(false)
      } else {
        if (res <= 0) {
          cb(false)
        } else {
          console.log('plop')
          DB.token.remove({
            user: user,
            token: Crypto.SHA256(token).toString()
          }, {}, function (err) {
            console.log('plop')
            if (err) {
              LogWorker.error(err)
              cb(false)
            } else {
              LogWorker.info(`${user} logout.`)
              cb(true)
            }
          })
        }
      }
    })
  }

  setTimeout(logout)
}

Auth.prototype.register = function (user, pass, invite, cb) {
  var self = this
  var register = function () {
    DB.invitation.find({hash: invite}, function (err, res) {
      if (err) {
        LogWorker.error(err)
        cb(false)<commit_msg>remove useless logs<commit_after>'use strict'

var fs = require('fs')
var Path = require('path')
var Rand = require('crypto-rand')
var Crypto = require('crypto-js')
var Database = require(Path.join(__base, 'src/database/client.js'))
var DB = {
  user: new Database('user', __config.database.host, __config.database.port, __DBtoken),
  invitation: new Database('invitation', __config.database.host, __config.database.port, __DBtoken),
  token: new Database('token', __config.database.host, __config.database.port, __DBtoken)
}

var Log = require(Path.join(__base, 'src/worker/log.js'))
var LogWorker = new Log({
  module: 'Auth'
})

function Auth () {
  var self = this

  setInterval(self.cleanToken, 60000)
}

Auth.prototype.login = function (user, pass, ip, cb) {
  var self = this
  var login = function () {
    DB.user.find({
      user: user,
      password: <PASSWORD>
    }, function (err, res) {
      if (err) {
        LogWorker.error(err)
        cb(false)
      } else {
        if (res <= 0) {
          cb(false)
        } else {
          self.genUserToken(user, pass, function (token) {
            LogWorker.info(`${user} login from ${ip}.`)
            cb(token)
          })
        }
      }
    })
  }

  setTimeout(login)
}

Auth.prototype.logout = function (user, token, cb) {
  var self = this
  var logout = function () {
    DB.token.find({
      user: user,
      token: Crypto.SHA256(token).toString()
    }, function (err, res) {
      if (err) {
        LogWorker.error(err)
        cb(false)
      } else {
        if (res <= 0) {
          cb(false)
        } else {
          DB.token.remove({
            user: user,
            token: Crypto.SHA256(token).toString()
          }, {}, function (err) {
            if (err) {
              LogWorker.error(err)
              cb(false)
            } else {
              LogWorker.info(`${user} logout.`)
              cb(true)
            }
          })
        }
      }
    })
  }

  setTimeout(logout)
}

Auth.prototype.register = function (user, pass, invite, cb) {
  var self = this
  var register = function () {
    DB.invitation.find({hash: invite}, function (err, res) {
      if (err) {
        LogWorker.error(err)
        cb(false)
{'fraction_non_alphanumeric': 0.14634146341463414, 'fraction_numerical': 0.005764966740576497, 'mean_word_length': 2.05416384563304, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '4967306', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1431, 'n_words': 325}