<commit_before>import {DatabaseObject} from '../type/model.d.ts'
import {Router, Request, Response, NextFunction} from 'express'
import * as jwt from 'jsonwebtoken'
import * as passport from 'passport'

export function getAuthenticationRoutes(model: DatabaseObject): Router {
  let router = Router()

  // route to add new accounts (not activated)
  router.route('/register')
  .post((req: Request, res: Response, next: NextFunction) => {
    let newUser = new model.user({
      email: req['body'].email,
      password: req['body'].password
    })
    newUser.save()
    .then((account) => {
      model.logger.info(`create: ${account}`)
      res.status(201).json(account)
    }, (err) => {
      model.logger.error(err)
      return next(err)
    })
  })

  /**
   * Check name and password against the database and provide a
   * token if authentication succeeded.
   */
  router.route('/signin')
  .post((req: Request, res: Response, next: NextFunction) => {
    model.user.findOne({ email: req['body'].email }).exec()
    .then((account) => {
      if (!account) { return next() }
      if (!account.activated) {
        return res.status(403).json({
          message: 'Account not activated',
          success: false
        })
      }
      account.comparePassword(req['body'].password)<commit_msg>automatic activation for dev<commit_after>import {DatabaseObject} from '../type/model.d.ts'
import {Router, Request, Response, NextFunction} from 'express'
import * as jwt from 'jsonwebtoken'
import * as passport from 'passport'

export function getAuthenticationRoutes(model: DatabaseObject): Router {
  let router = Router()

  // route to add new accounts (not activated)
  router.route('/register')
  .post((req: Request, res: Response, next: NextFunction) => {
    let newUser = new model.user({
      activated: true,
      email: req['body'].email,
      password: req['body'].password
    })
    newUser.save()
    .then((account) => {
      model.logger.info(`create: ${account}`)
      res.status(201).json(account)
    }, (err) => {
      model.logger.error(err)
      return next(err)
    })
  })

  /**
   * Check name and password against the database and provide a
   * token if authentication succeeded.
   */
  router.route('/signin')
  .post((req: Request, res: Response, next: NextFunction) => {
    model.user.findOne({ email: req['body'].email }).exec()
    .then((account) => {
      if (!account) { return next() }
      if (!account.activated) {
        return res.status(403).json({
          message: 'Account not activated',
          success: false
        })
      }
      account.comparePassword(req['body'].password)
{'fraction_non_alphanumeric': 0.15135542168674698, 'fraction_numerical': 0.004518072289156626, 'mean_word_length': 3.0379939209726445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3258239', 'n_tokens_mistral': 789, 'n_tokens_neox': 770, 'n_words': 206}