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

100% Statements 8/8
100% Branches 0/0
100% Functions 2/2
100% Lines 8/8
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                                               
'use strict';
 
/**
 * 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 + '://' + req.get('host') + 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();
  };
};