lib/validate.js
function retrievePGTFromPGTIOU(req, res, callback, pgtIou, options) {
  var logger = utils.getLogger(req, options);
  logger.info('Trying to retrieve pgtId from pgtIou...');

  req.sessionStore.get(pgtIou, function(err, session) {
    /* istanbul ignore if */
    if (err) {
      logger.error('Get pgtId from sessionStore failed!');
      logger.error(err);
      req.sessionStore.destroy(pgtIou);
      return callback(function(req, res, next) {
        res.status(500).send({
          message: 'Get pgtId from sessionStore failed!',
          error: err
        });
      });
    }

    if (session && session.pgtId) {
      var lastUrl = utils.getLastUrl(req, options, logger);

      if (!req.session || req.session && !req.session.cas) {
        logger.error('Here session.cas should not be empty!', req.session);
        req.session.cas = {};
      }

      req.session.cas.pgt = session.pgtId;

      req.session.save(function(err) {
        /* istanbul ignore if */
        if (err) {
          logger.error('Trying to save session failed!');
          logger.error(err);
          return callback(function(req, res, next) {
            res.status(500).send({
              message: 'Trying to save session failed!',
              error: err
            });
          });
        }

        // 释放
        req.sessionStore.destroy(pgtIou);

        /* istanbul ignore if */ // 测一次就够了
        lastUrl = getLastUrl(req, res, options, logger, lastUrl);

        logger.info('CAS proxy mode login and validation succeed, pgtId finded. Redirecting to lastUrl: ' + lastUrl);
        return callback(function(req, res, next) {
          res.redirect(302, lastUrl);
        });
      });
    } else {
      logger.error('CAS proxy mode login and validation succeed, but can\' find pgtId from pgtIou: `' + pgtIou + '`, maybe something wrong with sessionStroe!');
      callback(function(req, res, next) {
        res.status(401).send({
          message: 'CAS proxy mode login and validation succeed, but can\' find pgtId from pgtIou: `' + pgtIou + '`, maybe something wrong with sessionStroe!'
        });
      });
    }
  });
}
function retrievePGTFromPGTIOU(req, res, callback, pgtIou, options) {
  var logger = utils.getLogger(req, options);
  logger.info('Trying to retrieve pgtId from pgtIou...');

  req.sessionStore.get(pgtIou, function(err, session) {
    /* istanbul ignore if */
    if (err) {
      logger.error('Get pgtId from sessionStore failed!');
      logger.error(err);
      req.sessionStore.destroy(pgtIou);
      return callback(function(req, res, next) {
        res.status(500).send({
          message: 'Get pgtId from sessionStore failed!',
          error: err
        });
      });
    }

    if (session && session.pgtId) {
      var lastUrl = utils.getLastUrl(req, options, logger);

      if (!req.session || req.session && !req.session.cas) {
        logger.error('Here session.cas should not be empty!', req.session);
        req.session.cas = {};
      }

      req.session.cas.pgt = session.pgtId;

      req.session.save(function(err) {
        /* istanbul ignore if */
        if (err) {
          logger.error('Trying to save session failed!');
          logger.error(err);
          return callback(function(req, res, next) {
            res.status(500).send({
              message: 'Trying to save session failed!',
              error: err
            });
          });
        }

        // 释放
        req.sessionStore.destroy(pgtIou);

        /* istanbul ignore if */ // 测一次就够了
        lastUrl = getLastUrl(req, res, options, logger, lastUrl);

        logger.info('CAS proxy mode login and validation succeed, pgtId finded. Redirecting to lastUrl: ' + lastUrl);
        return callback(function(req, res, next) {
          res.redirect(302, lastUrl);
        });
      });
    } else {
      logger.error('CAS proxy mode login and validation succeed, but can\' find pgtId from pgtIou: `' + pgtIou + '`, maybe something wrong with sessionStroe!');
      callback(function(req, res, next) {
        res.status(401).send({
          message: 'CAS proxy mode login and validation succeed, but can\' find pgtId from pgtIou: `' + pgtIou + '`, maybe something wrong with sessionStroe!'
        });
      });
    }
  });
}
function retrievePGTFromPGTIOU ( req , res , callback , pgtIou , options ) { var logger = utils . getLogger ( req , options ) ; logger . info ( 'Trying to retrieve pgtId from pgtIou...' ) ; req . sessionStore . get ( pgtIou , function ( err , session ) { /* istanbul ignore if */ if ( err ) { logger . error ( 'Get pgtId from sessionStore failed!' ) ; logger . error ( err ) ; req . sessionStore . destroy ( pgtIou ) ; return callback ( function ( req , res , next ) { res . status ( 500 ) . send ( { message : 'Get pgtId from sessionStore failed!' , error : err } ) ; } ) ; } if ( session && session . pgtId ) { var lastUrl = utils . getLastUrl ( req , options , logger ) ; if ( ! req . session || req . session && ! req . session . cas ) { logger . error ( 'Here session.cas should not be empty!' , req . session ) ; req . session . cas = { } ; } req . session . cas . pgt = session . pgtId ; req . session . save ( function ( err ) { /* istanbul ignore if */ if ( err ) { logger . error ( 'Trying to save session failed!' ) ; logger . error ( err ) ; return callback ( function ( req , res , next ) { res . status ( 500 ) . send ( { message : 'Trying to save session failed!' , error : err } ) ; } ) ; } // 释放 req . sessionStore . destroy ( pgtIou ) ; /* istanbul ignore if */ // 测一次就够了 lastUrl = getLastUrl ( req , res , options , logger , lastUrl ) ; logger . info ( 'CAS proxy mode login and validation succeed, pgtId finded. Redirecting to lastUrl: ' + lastUrl ) ; return callback ( function ( req , res , next ) { res . redirect ( 302 , lastUrl ) ; } ) ; } ) ; } else { logger . error ( 'CAS proxy mode login and validation succeed, but can\' find pgtId from pgtIou: `' + pgtIou + '`, maybe something wrong with sessionStroe!' ) ; callback ( function ( req , res , next ) { res . status ( 401 ) . send ( { message : 'CAS proxy mode login and validation succeed, but can\' find pgtId from pgtIou: `' + pgtIou + '`, maybe something wrong with sessionStroe!' } ) ; } ) ; } } ) ; }
Find PGT by PGTIOU

@param req
@param res
@param callback
@param pgtIou
@param options
Find PGT by PGTIOU