controller/token_controller.js
function (req, res, next) {
  if (periodic.app.controller.extension.reactadmin) {
    let reactadmin = periodic.app.controller.extension.reactadmin;
		// console.log({ reactadmin });
		// console.log('ensureAuthenticated req.session', req.session);
		// console.log('ensureAuthenticated req.user', req.user);
    next();
  } else {
    let adminPostRoute = res.locals.adminPostRoute || 'auth';
    var token = req.controllerData.token,
			// current_user,
      decode_token;

    decode(token, function (err, decode) {
      if (err) {
        CoreController.handleDocumentQueryErrorResponse({
          err: err,
          res: res,
          req: req,
          errorflash: err.message,
        });
      }			else {
        decode_token = decode;
				//Find the User by their token
        User.findOne({
          'attributes.reset_token': token,
        }, function (err, found_user) {
          if (err || !found_user) {
            req.flash('error', 'Password reset token is invalid.');
            res.redirect(loginExtSettings.settings.authLoginPath);
          }
					// current_user = found_user;
					//Check to make sure token hasn't expired

					//Check to make sure token is valid and sign by us
          else if (found_user.email !== decode_token.email && found_user.api_key !== decode_token.api_key) {
            req.flash('error', 'This token is not valid please try again');
            res.redirect(loginExtSettings.settings.authLoginPath);
          }					else {
            CoreController.getPluginViewDefaultTemplate({
              viewname: 'user/reset',
              themefileext: appSettings.templatefileextension,
              extname: 'periodicjs.ext.login',
            },
							function (err, templatepath) {
  CoreController.handleDocumentQueryRender({
    res: res,
    req: req,
    renderView: templatepath,
    responseData: {
      pagedata: {
        title: 'Reset Password',
        current_user: found_user,
      },
      user: req.user,
      adminPostRoute: adminPostRoute,
    },
  });
});
          }
        });
      }
    });
  }
}
function (req, res, next) {
  if (periodic.app.controller.extension.reactadmin) {
    let reactadmin = periodic.app.controller.extension.reactadmin;
		// console.log({ reactadmin });
		// console.log('ensureAuthenticated req.session', req.session);
		// console.log('ensureAuthenticated req.user', req.user);
    next();
  } else {
    let adminPostRoute = res.locals.adminPostRoute || 'auth';
    var token = req.controllerData.token,
			// current_user,
      decode_token;

    decode(token, function (err, decode) {
      if (err) {
        CoreController.handleDocumentQueryErrorResponse({
          err: err,
          res: res,
          req: req,
          errorflash: err.message,
        });
      }			else {
        decode_token = decode;
				//Find the User by their token
        User.findOne({
          'attributes.reset_token': token,
        }, function (err, found_user) {
          if (err || !found_user) {
            req.flash('error', 'Password reset token is invalid.');
            res.redirect(loginExtSettings.settings.authLoginPath);
          }
					// current_user = found_user;
					//Check to make sure token hasn't expired

					//Check to make sure token is valid and sign by us
          else if (found_user.email !== decode_token.email && found_user.api_key !== decode_token.api_key) {
            req.flash('error', 'This token is not valid please try again');
            res.redirect(loginExtSettings.settings.authLoginPath);
          }					else {
            CoreController.getPluginViewDefaultTemplate({
              viewname: 'user/reset',
              themefileext: appSettings.templatefileextension,
              extname: 'periodicjs.ext.login',
            },
							function (err, templatepath) {
  CoreController.handleDocumentQueryRender({
    res: res,
    req: req,
    renderView: templatepath,
    responseData: {
      pagedata: {
        title: 'Reset Password',
        current_user: found_user,
      },
      user: req.user,
      adminPostRoute: adminPostRoute,
    },
  });
});
          }
        });
      }
    });
  }
}
function ( req , res , next ) { if ( periodic . app . controller . extension . reactadmin ) { let reactadmin = periodic . app . controller . extension . reactadmin ; // console.log({ reactadmin }); // console.log('ensureAuthenticated req.session', req.session); // console.log('ensureAuthenticated req.user', req.user); next ( ) ; } else { let adminPostRoute = res . locals . adminPostRoute || 'auth' ; var token = req . controllerData . token , // current_user, decode_token ; decode ( token , function ( err , decode ) { if ( err ) { CoreController . handleDocumentQueryErrorResponse ( { err : err , res : res , req : req , errorflash : err . message , } ) ; } else { decode_token = decode ; //Find the User by their token User . findOne ( { 'attributes.reset_token' : token , } , function ( err , found_user ) { if ( err || ! found_user ) { req . flash ( 'error' , 'Password reset token is invalid.' ) ; res . redirect ( loginExtSettings . settings . authLoginPath ) ; } // current_user = found_user; //Check to make sure token hasn't expired //Check to make sure token is valid and sign by us else if ( found_user . email !== decode_token . email && found_user . api_key !== decode_token . api_key ) { req . flash ( 'error' , 'This token is not valid please try again' ) ; res . redirect ( loginExtSettings . settings . authLoginPath ) ; } else { CoreController . getPluginViewDefaultTemplate ( { viewname : 'user/reset' , themefileext : appSettings . templatefileextension , extname : 'periodicjs.ext.login' , } , function ( err , templatepath ) { CoreController . handleDocumentQueryRender ( { res : res , req : req , renderView : templatepath , responseData : { pagedata : { title : 'Reset Password' , current_user : found_user , } , user : req . user , adminPostRoute : adminPostRoute , } , } ) ; } ) ; } } ) ; } } ) ; } }
GET if the user token is vaild show the change password page
GET if the user token is vaild show the change password page