<commit_before>var forms = require('./forms');
var stormpath = require('./index');


module.exports.login = function(req, res) {
  req.app.set('views', __dirname + '/views');
  req.app.set('view engine', 'jade');
  res.locals.csrfToken = req.csrfToken();

  forms.loginForm.handle(req, {
    // If we get here, it means the user is submitting a login request, so we
    // should attempt to log the user into their account.
    success: function(form) {
      stormpath.application.authenticateAccount({
        username: form.data.login,
        password: form.data.password
      }, function(err, result) {
        if (err) {
          res.render('login', { error: err.userMessage, form: form });
        } else {
          result.getAccount(function(err, account) {
            if (err) {
              res.render('login', { error: err.userMessage, form: form });
            } else {
              req.session.user = account;
              res.locals.user = account;
              res.redirect(302, req.app.get('stormpathRedirectUrl'));
            }
          });
        }
      });
    },

    // If we get here, it means the user didn't supply required form fields.
    error: function(form) {
      res.render('login', { error: 'Required fields missing.', form: form });
    },

    // If we get here, it means the user is doing a simple GET request, so we
    // should just render the login template.
    empty: function(form) {
      res.render('login', { form: form });
    }
  });
}


module.exports.logout = function(req, res) {
  req.session.reset();
  res.redirect('/');
}<commit_msg>Fixing bug in logout controller.<commit_after>var forms = require('./forms');
var stormpath = require('./index');


module.exports.login = function(req, res) {
  req.app.set('views', __dirname + '/views');
  req.app.set('view engine', 'jade');
  res.locals.csrfToken = req.csrfToken();

  forms.loginForm.handle(req, {
    // If we get here, it means the user is submitting a login request, so we
    // should attempt to log the user into their account.
    success: function(form) {
      stormpath.application.authenticateAccount({
        username: form.data.login,
        password: form.data.password
      }, function(err, result) {
        if (err) {
          res.render('login', { error: err.userMessage, form: form });
        } else {
          result.getAccount(function(err, account) {
            if (err) {
              res.render('login', { error: err.userMessage, form: form });
            } else {
              req.session.user = account;
              res.locals.user = account;
              res.redirect(302, req.app.get('stormpathRedirectUrl'));
            }
          });
        }
      });
    },

    // If we get here, it means the user didn't supply required form fields.
    error: function(form) {
      res.render('login', { error: 'Required fields missing.', form: form });
    },

    // If we get here, it means the user is doing a simple GET request, so we
    // should just render the login template.
    empty: function(form) {
      res.render('login', { form: form });
    }
  });
}


module.exports.logout = function(req, res) {
  if (req.session) {
    req.session.reset();
  }
  res.redirect('/');
}
{'fraction_non_alphanumeric': 0.1440886699507389, 'fraction_numerical': 0.0018472906403940886, 'mean_word_length': 2.2785065590312814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2042335', 'n_tokens_mistral': 957, 'n_tokens_neox': 935, 'n_words': 264}