text: // Generated by CoffeeScript 1.6.3
  (function() {
    var crypto, lm;
  
    crypto = require('crypto');
  
    lm = require('./login-manager.js');
  
    module.exports = function(req, res, keygen) {
      var hash, sid, timestamp, username, _ref;
      res.writeHead(200, {
        'Content-Type': 'text/html'
      });
      _ref = req.body, username = _ref.username, hash = _ref.hash, sid = _ref.sid;
      if (hash != null) {
        timestamp = parseInt((new Date().getTime()) / 1000 / 30);
        keygen(username, function(key) {
          var hmac;
          key = (new Buffer(key)).toString('hex');
          hmac = crypto.createHmac('sha512', key);
          hmac.setEncoding('hex');
          hmac.write([username, sid, timestamp].join(''));
          hmac.end();
          if (hash === hmac.read()) {
            lm.login(sid);
            return res.write(JSON.stringify({
              status: "success"
            }));
          } else {
            return res.write(JSON.stringify({
              status: "error",
              error: "hash not match"
            }));
          }
        });
      } else {
        res.write(JSON.stringify({
          login: lm.test(sid)
        }));
      }
      return res.end();
    };
  
  }).call(this);
  