<commit_before>'use strict';

var helpers = require('../helpers');
var middleware = require('../middleware');
var url = require('url');

/**
 * This controller handles a Stormpath ID Site authentication.  Once a user is
 * authenticated, they'll be returned to the site.
 *
 * @method
 *
 * @param {Object} req - The http request.
 * @param {Object} res - The http response.
 */
module.exports = function (req, res) {
  var application = req.app.get('stormpathApplication');
  var config = req.app.get('stormpathConfig');
  var logger = req.app.get('stormpathLogger');

  application.handleIdSiteCallback(req.originalUrl, function (err, result) {
    if (err) {
      logger.info('While attempting to authenticate a user via ID site, the callback verification failed.');
      return res.status(500).end(err.toString());
    }

    if (result.status === 'LOGOUT') {
      middleware.deleteCookies(req, res);
      res.redirect(302, config.web.idSite.nextUri);
    } else if (result.status === 'AUTHENTICATED') {
      var nextUrl = url.parse(req.query.next || '').path || config.web.idSite.nextUri;

      helpers.createIdSiteSession(result.account, req, res);
      res.redirect(302, nextUrl);
    } else {
      res.status(500).end('Unknown ID site result status: ' + result.status);
    }
  });
};<commit_msg>add support for idSiteVerify() registered status<commit_after>'use strict';

var helpers = require('../helpers');
var middleware = require('../middleware');
var url = require('url');

/**
 * This controller handles a Stormpath ID Site authentication.  Once a user is
 * authenticated, they'll be returned to the site.
 *
 * @method
 *
 * @param {Object} req - The http request.
 * @param {Object} res - The http response.
 */
module.exports = function (req, res) {
  var application = req.app.get('stormpathApplication');
  var config = req.app.get('stormpathConfig');
  var logger = req.app.get('stormpathLogger');

  application.handleIdSiteCallback(req.originalUrl, function (err, result) {
    if (err) {
      logger.info('While attempting to authenticate a user via ID site, the callback verification failed.');
      return res.status(500).end(err.toString());
    }

    var idSiteNextUri = config.web.idSite.nextUri;

    switch (result.status) {
      case 'LOGOUT':
        middleware.deleteCookies(req, res);
        res.redirect(302, idSiteNextUri);
        break;
      case 'REGISTERED':
      case 'AUTHENTICATED':
        if (result.status === 'AUTHENTICATED' || (result.status === 'REGISTERED' && config.web.register.autoLogin)) {
          helpers.createIdSiteSession(result.account, req, res);
        }

        var nextUrl = url.parse(req.query.next || '').path || idSiteNextUri;

        res.redirect(302, nextUrl);
        break;
      default:
        res.status(500).end('Unknown ID site result status: ' + result.status);
        break;
    }
  });
};
{'fraction_non_alphanumeric': 0.14463667820069204, 'fraction_numerical': 0.008304498269896194, 'mean_word_length': 3.3343328335832085, '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': '7299509', 'n_tokens_mistral': 882, 'n_tokens_neox': 854, 'n_words': 228}