<commit_before>const models = require('../models');

module.exports = {
  createUser(req, res) {
    return models.User
      .create({
        firstName: req.body.firstName,
        lastName: req.body.lastName,
        email: req.body.email,
        role: req.body.role,
        password: req.body.password,
      })
      .then(result => res.status(201).send(result))
      .catch(error => res.status(400).send(error));
  },
};<commit_msg>Add user signup feature using json web token<commit_after>import bcryptjs from 'bcryptjs';
import jsonwebtoken from 'jsonwebtoken';
import User from '../module/User';

const jwt = jsonwebtoken;

module.exports = {
  createUser(req, res) {
    const hash = bcryptjs.hashSync(req.body.password, 8);
    new User().signUp(
      req.body.firstName,
      req.body.lastName,
      req.body.email,
      req.body.role,
      hash
    )
      .then((user) => {
        const token = jwt.sign({ id: user.id, email: user.email }, process.env.JWT_SECRET, {
          expiresIn: 86400
        });
        res.status(201).send({ msg: 'Sign up successful', token });
      })
      .catch(error => res.status(400).send(error));
  },
};
{'fraction_non_alphanumeric': 0.15378006872852235, 'fraction_numerical': 0.015463917525773196, 'mean_word_length': 2.5736196319018405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2199945', 'n_tokens_mistral': 396, 'n_tokens_neox': 383, 'n_words': 78}