all files / express-stormpath/lib/controllers/ id-site-redirect.js

22.22% Statements 2/9
100% Branches 0/0
0% Functions 0/2
22.22% Lines 2/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                                                   
'use strict';
 
var getHost = require('../helpers/get-host');
 
/**
 * This controller registers a new user using Stormpath's hosted ID Site
 * service.  This will redirect the user to the ID site which allows a user to
 * register.
 *
 * @method
 *
 * @param {Object} req - The http request.
 * @param {Object} res - The http response.
 */
module.exports = function (options) {
  return function (req, res) {
    var application = req.app.get('stormpathApplication');
    var config = req.app.get('stormpathConfig');
    var cbUri = req.protocol + '://' + getHost(req) + config.web.idSite.uri;
 
    var url = application.createIdSiteUrl({
      callbackUri: cbUri,
      logout: options.logout,
      path: options.path
    });
 
    res.writeHead(302, {
      'Cache-Control': 'no-store',
      'Location': url,
      'Pragma': 'no-cache'
    });
 
    res.end();
  };
};