<commit_before>import express from 'express';
import bcrypt from 'bcrypt';
import genToken from '../config/auth/jwtGenerator';
import User from '../db/controllers/users';
import knexModule from 'knex';
import bookshelfModule from 'bookshelf';
import { development as devconfig } from '../../knexfile';
import bookshelfBcrypt from 'bookshelf-bcrypt';
const { bookshelf } = require('../db/init').default;
const knex = knexModule(devconfig);
const knexdb = bookshelfModule(knex);
let usersModel = require('../db/models/users').default;
knexdb.plugin(bookshelfBcrypt);
usersModel = usersModel(knexdb);

const router = express.Router();

router.post('/', (req, res) => {
  const reqEmail = req.body.email;
  const reqPassword = req.body.password;

  if (reqEmail && reqPassword) {
    User.getUserByEmail({ email: reqEmail }, usersModel)
      .then((user) => {
        if (!user) {
          console.log('user not found');
          res.status(401).send({ message: 'invalid username or password' });
        } else {
          bcrypt.compare(reqPassword, user.attributes.password_hash, (err, match) => {
            if (err) {
              console.log(err.message);
              res.status(500).send(err.message);
            }
            if (match) {
              console.log('password match');
              const token = genToken(user.id);
              const { id } = user;
              res.status(201).json({
                message: 'login successful',
                token,
                id 
              });
            } else {
              console.log('invalid password');
              res.status(401).json({ message: 'invalid username or password' });
            }
          });
        }
      });
  } else {
    res.status(401).json({ message: 'invalid username or password' });
  }
});

export default router;<commit_msg>Remove trailing space on line 41<commit_after>import express from 'express';
import bcrypt from 'bcrypt';
import genToken from '../config/auth/jwtGenerator';
import User from '../db/controllers/users';
import knexModule from 'knex';
import bookshelfModule from 'bookshelf';
import { development as devconfig } from '../../knexfile';
import bookshelfBcrypt from 'bookshelf-bcrypt';
const { bookshelf } = require('../db/init').default;
const knex = knexModule(devconfig);
const knexdb = bookshelfModule(knex);
let usersModel = require('../db/models/users').default;
knexdb.plugin(bookshelfBcrypt);
usersModel = usersModel(knexdb);

const router = express.Router();

router.post('/', (req, res) => {
  const reqEmail = req.body.email;
  const reqPassword = req.body.password;

  if (reqEmail && reqPassword) {
    User.getUserByEmail({ email: reqEmail }, usersModel)
      .then((user) => {
        if (!user) {
          console.log('user not found');
          res.status(401).send({ message: 'invalid username or password' });
        } else {
          bcrypt.compare(reqPassword, user.attributes.password_hash, (err, match) => {
            if (err) {
              console.log(err.message);
              res.status(500).send(err.message);
            }
            if (match) {
              console.log('password match');
              const token = genToken(user.id);
              const { id } = user;
              res.status(201).json({
                message: 'login successful',
                token,
                id
              });
            } else {
              console.log('invalid password');
              res.status(401).json({ message: 'invalid username or password' });
            }
          });
        }
      });
  } else {
    res.status(401).json({ message: 'invalid username or password' });
  }
});

export default router;
{'fraction_non_alphanumeric': 0.1420086393088553, 'fraction_numerical': 0.008639308855291577, 'mean_word_length': 2.29919857524488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4797489', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1018, 'n_words': 252}