<commit_before>Organization = require '../../models/organization'
crypto = require 'crypto'
hexDigest = (string)->
  sha = crypto.createHash('sha256');
  sha.update('awesome')
  sha.digest('hex')

routes = (app) ->

  app.get '/login', (req, res) ->
    res.render "#{__dirname}/views/login",
      title: 'Login',
      stylesheet: 'login'

  app.post '/sessions', (req, res, next) ->
    errMsg = "Org Name or Password is invalid. Try again"
    if req.body.name and req.body.password
      Organization.findOne name: req.body.name, (err, org) ->
        if org and org.hashed_password == <PASSWORD>(req.body.password)
          req.session.org_id = org.id
          req.flash 'info',
            "You are logged in as #{req.session.currentOrg}"
          res.redirect '/dashboard'
        else
          req.flash 'error', errMsg
          res.redirect '/login'
    else
      req.flash 'error', errMsg
      res.redirect '/login'

  app.del '/sessions', (req, res) ->
    req.session.regenerate (err) ->
      req.flash 'info', 'You have been logged out.'
      res.redirect '/login'

module.exports = routes
<commit_msg>Fix the flash when logging in<commit_after>Organization = require '../../models/organization'
crypto = require 'crypto'
hexDigest = (string)->
  sha = crypto.createHash('sha256');
  sha.update('awesome')
  sha.digest('hex')

routes = (app) ->

  app.get '/login', (req, res) ->
    res.render "#{__dirname}/views/login",
      title: 'Login',
      stylesheet: 'login'

  app.post '/sessions', (req, res, next) ->
    errMsg = "Org Name or Password is invalid. Try again"
    if req.body.name and req.body.password
      Organization.findOne name: req.body.name, (err, org) ->
        if org and org.hashed_password == <PASSWORD>(req.body.password)
          req.session.org_id = org.id
          req.flash 'info', "You are logged in as #{org.name}"
          res.redirect '/dashboard'
        else
          req.flash 'error', errMsg
          res.redirect '/login'
    else
      req.flash 'error', errMsg
      res.redirect '/login'

  app.del '/sessions', (req, res) ->
    req.session.regenerate (err) ->
      req.flash 'info', 'You have been logged out.'
      res.redirect '/login'

module.exports = routes

{'fraction_non_alphanumeric': 0.15223214285714284, 'fraction_numerical': 0.0026785714285714286, 'mean_word_length': 2.507042253521127, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '2626402', 'n_tokens_mistral': 714, 'n_tokens_neox': 698, 'n_words': 191}