<commit_before>const bcrypt = require('bcrypt');

const UserDAO = require('../services/UserDAO');
const createToken = require('../utils/createToken');

class AuthController {
  static login(req, res) {
    const { email, password } = req.body;
    UserDAO.findBy({ email })
      .then((user) => {
        if (!bcrypt.compareSync(password, user.password)) {
          res.status(401).end();
        } else {
          req.session.currentUser = user;
          const token = createToken(user);
          res.cookie('token', token);
          res.status(200).json(token);
        }
      })
      .catch((err) => {
        console.error(err);
        res.status(401).end();
      });
  }
  static signUp(req, res) {
    const email = req.body.email;
    const username = req.body.username;
    let password = <PASSWORD>;
    if (email.length > 0 && password.length > 0) {
      password = <PASSWORD>.hashSync(password, 10);
      UserDAO.create({ email, password, username })
          .then((user) => {
            req.session.currentUser = user;
            const token = createToken(user);
            res.cookie('token', token);
            res.status(200).json(user);
          })
          .catch((err) => res.status(500).json(err));
    } else {
      res.status(400).end();
    }
  }
  static signOut(req, res) {
    req.session.currentUser = null;
    res.clearCookie('token');
    res.status(204).end();
  }<commit_msg>return token from signup route<commit_after>const bcrypt = require('bcrypt');

const UserDAO = require('../services/UserDAO');
const createToken = require('../utils/createToken');

class AuthController {
  static login(req, res) {
    const { email, password } = req.body;
    UserDAO.findBy({ email })
      .then((user) => {
        if (!bcrypt.compareSync(password, user.password)) {
          res.status(401).end();
        } else {
          req.session.currentUser = user;
          const token = createToken(user);
          res.cookie('token', token);
          res.status(200).json(token);
        }
      })
      .catch((err) => {
        console.error(err);
        res.status(401).end();
      });
  }
  static signUp(req, res) {
    const email = req.body.email;
    const username = req.body.username;
    let password = <PASSWORD>;
    if (email.length > 0 && password.length > 0) {
      password = bcrypt.hashSync(password, 10);
      UserDAO.create({ email, password, username })
          .then((user) => {
            req.session.currentUser = user;
            const token = createToken(user);
            res.cookie('token', token);
            res.status(200).json(token);
          })
          .catch((err) => res.status(500).json(err));
    } else {
      res.status(400).end();
    }
  }
  static signOut(req, res) {
    req.session.currentUser = null;
    res.clearCookie('token');
    res.status(204).end();
  }
{'fraction_non_alphanumeric': 0.16317991631799164, 'fraction_numerical': 0.017433751743375175, 'mean_word_length': 2.234498308906426, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '2955230', 'n_tokens_mistral': 911, 'n_tokens_neox': 873, 'n_words': 166}