'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _fsExtra = require('fs-extra');

var _fsExtra2 = _interopRequireDefault(_fsExtra);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _cli = require('../../../../cli');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var route = function route(req, res) {
  var resHtml = '';
  if (typeof req.query.token !== 'undefined' && req.query.token !== null) {
    _cli.User.utils.findByResetPasswordToken(req.query.token, function () {

      var page = _path2.default.join(__dirname + '/../../../views/users/reset.html');
      if (_cli.coreUtils.file.exist(page)) {
        resHtml = _fsExtra2.default.readFileSync(page, 'utf8');
      }

      var template = _cli.Handlebars.compile(resHtml, { noEscape: true });

      var tmp = template({
        csrfToken: res.locals.csrfToken,
        config: JSON.stringify(_cli.config),
        express: {
          req: req,
          res: res
        },
        token: req.query.token,
        info: req.flash('info')
      });

      return res.send(tmp);
    });
  } else {
    res.redirect('/abe/users/forgot');
  }
};

exports.default = route;