<commit_before>var tsModule = require('../shared/Module.js');
var databaseFactory = require('../shared/DatabaseFactory.js');
var fs = require('fs');
// sign with default (HMAC SHA256)
var jwt = require('jsonwebtoken');

// sign with RSA SHA256
var cert = fs.readFileSync('rsa');  // get private key
var tsModuleLogin = function(){
    var obj = tsModule();

    obj.init = function(user, request, reply, errorHandler){
    obj.user = user;
    obj.request = request;
    obj.reply = reply;
    obj.errorHandler = errorHandler;

    obj.userdb = databaseFactory('userdb', user);
    //obj.usersession = databaseFactory()
  };
  obj.run = function(){
    obj.userdb.get(parseInt(obj.request.event.RIN)).then(
      function(res){
        if(res!==null){ //user Exists
	  console.log('asdfasdf');
          if (obj.request.event.password === res){//password is correct
            //generate token
            var data = {
              "RIN": obj.request.event.RIN,
              "expiresIn" : "2h"
            };

            var token = jwt.sign(data, cert, { algorithm: 'RS256'});
            console.log(token);

            console.log("Success");
            obj.reply.send(token);
          }<commit_msg>Style fix<commit_after>var tsModule = require('../shared/Module.js');
var databaseFactory = require('../shared/DatabaseFactory.js');
var fs = require('fs');
// sign with default (HMAC SHA256)
var jwt = require('jsonwebtoken');

// sign with RSA SHA256
var cert = fs.readFileSync('rsa');  // get private key

var tsModuleLogin = function(){
  var obj = tsModule();

  obj.init = function(user, request, reply, errorHandler){
    obj.user = user;
    obj.request = request;
    obj.reply = reply;
    obj.errorHandler = errorHandler;

    obj.userdb = databaseFactory('userdb', user);
    //obj.usersession = databaseFactory()
  };
  obj.run = function(){
    obj.userdb.get(parseInt(obj.request.event.RIN)).then(
      function(res){
        if(res!==null){ //user Exists
          if (obj.request.event.password === res){//password is correct
            //generate token
            var data = {
              "RIN": obj.request.event.RIN,
              "expiresIn" : "2h"
            };

            var token = jwt.sign(data, cert, { algorithm: 'RS256'});
            console.log('Generated token:', token);

            console.log("Success");
            obj.reply.send(token);
          }
{'fraction_non_alphanumeric': 0.15397419891801914, 'fraction_numerical': 0.008322929671244279, 'mean_word_length': 2.4245014245014245, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3919646', 'n_tokens_mistral': 737, 'n_tokens_neox': 714, 'n_words': 164}