<commit_before>import Router from 'koa-router';
import jwt from 'jsonwebtoken';
import CONFIG from '../config';
import bcrypt from 'bcrypt';

const router = new Router();

router.post('/login', async (ctx, next) =>{
  const {username} = ctx.request.body;
  const user = {
    id: 1,
    username: 'john_doe',
    password: <PASSWORD>', //123456
    email: '<EMAIL>',
    permission: 7,
    status: 1,
    updated_at: '2017-08-31 00:00:00',
    created_at: '2017-08-31 00:00:00'
  }; //I pretend this user was found from database

  const checkPwd = await bcrypt.compare( ctx.request.body.password, user.password );

  if ( checkPwd ) {
    const payload = {
      id: user.id,
      username: user.username,
      status: user.status,
      updated_at: user.updated_at
    };

    //Web need to include status + updated_at in to the secret 
    // Then we can automatically force user logout when their account was changed (block, change password, etc)
    const superSecret = CONFIG.JWT.secret + user.status + user.updated_at;
    const token = jwt.sign(payload, superSecret);
    ctx.body = {
      error: false,
      token: token,
      user: user,
      message: 'Logged in successfully!'
    }
  } else {
    ctx.body = {
      message: 'Login fail!'
    }
  }
  await next();
});


export default router;<commit_msg>remove users password before send it to clientt<commit_after>import Router from 'koa-router';
import jwt from 'jsonwebtoken';
import CONFIG from '../config';
import bcrypt from 'bcrypt';

const router = new Router();

router.post('/login', async (ctx, next) =>{
  const {username} = ctx.request.body;
  const user = {
    id: 1,
    username: 'john_doe',
    password: <PASSWORD>', //123456
    email: '<EMAIL>',
    permission: 7,
    status: 1,
    updated_at: '2017-08-31 00:00:00',
    created_at: '2017-08-31 00:00:00'
  }; //I pretend this user was found from database

  const checkPwd = await bcrypt.compare( ctx.request.body.password, user.password );

  if ( checkPwd ) {
    const payload = {
      id: user.id,
      username: user.username,
      status: user.status,
      updated_at: user.updated_at
    };

    //Web need to include status + updated_at in to the secret 
    // Then we can automatically force user logout when their account was changed (block, change password, etc)
    const superSecret = CONFIG.JWT.secret + user.status + user.updated_at;
    const token = jwt.sign(payload, superSecret);
    delete user.password;
    ctx.body = {
      error: false,
      token: token,
      user: user,
      message: 'Logged in successfully!'
    }
  } else {
    ctx.body = {
      message: 'Login fail!'
    }
  }
  await next();
});


export default router;
{'fraction_non_alphanumeric': 0.12490761271249076, 'fraction_numerical': 0.027346637102734665, 'mean_word_length': 2.8397163120567375, 'pattern_counts': {'":': 0, '<': 7, '<?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': '634329', 'n_tokens_mistral': 912, 'n_tokens_neox': 854, 'n_words': 268}