fix(core): remove unused code and add a comm-variable

This commit is contained in:
OldHawk
2018-03-16 17:41:51 +08:00
parent 29d138242b
commit 89962c594d
5 changed files with 12 additions and 61 deletions

View File

@@ -22,18 +22,13 @@ module.exports = {
* @cronTimeZone: timezone of cron
* @showDebugLog: if true, will console.log all debug info at server side and client side. when your site is prod env, please change this
* value to false, then console.log info is not output
* @setDefaultValueOnIndex: set app.domain and announce.url on renderer index
* if false, app.domain and announce.url used these config settings value
* if true, app.domain and announce.url used req.headers.host
* if web server used proxyPass setting, this should set to false
*/
app: {
name: commonEnvConfig.variable.site.site_name,
domain: commonEnvConfig.variable.site.site_domain,
showDemoWarningPopup: true,
cronTimeZone: 'Asia/Shanghai',
showDebugLog: true,
setDefaultValueOnIndex: false
showDebugLog: commonEnvConfig.variable.settings.console_debug_info || true
},
/**
@@ -95,7 +90,7 @@ module.exports = {
* @userHnrWarningCheckInterval: setting check users H&R warning interval time, default to 2 hours
*/
announce: {
url: '/announce',
url: commonEnvConfig.variable.site.site_domain + '/announce',
comment: commonEnvConfig.variable.site.site_name + ' group',
announceInterval: 60 * 1000 * 5,
announcePrefix: '{' + commonEnvConfig.variable.site.site_namekey + '}.',

View File

@@ -14,8 +14,7 @@ exports.renderIndex = function (req, res) {
req.user.addSignedIp(ip);
}
var cfg = setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
cfg = getSafeMeanTorrentConfig(cfg);
var cfg = getSafeMeanTorrentConfig(config.meanTorrentConfig);
res.render('modules/core/server/views/index', {
user: JSON.stringify(safeUserObject),
@@ -30,8 +29,7 @@ exports.renderIndex = function (req, res) {
exports.renderServerError = function (req, res) {
var safeUserObject = req.user || null;
var cfg = setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
cfg = getSafeMeanTorrentConfig(cfg);
var cfg = getSafeMeanTorrentConfig(config.meanTorrentConfig);
res.status(500).render('modules/core/server/views/500', {
user: JSON.stringify(safeUserObject),
@@ -48,8 +46,7 @@ exports.renderServerError = function (req, res) {
exports.renderNotFound = function (req, res) {
var safeUserObject = req.user || null;
var cfg = setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
cfg = getSafeMeanTorrentConfig(cfg);
var cfg = getSafeMeanTorrentConfig(config.meanTorrentConfig);
res.status(404).format({
'text/html': function () {
@@ -102,26 +99,3 @@ function getSafeMeanTorrentConfig(cfg) {
return newCfg;
}
/**
* setMeanTorrentConfigDefaultValue
* @param cfg
*/
function setMeanTorrentConfigDefaultValue(req, res, cfg) {
if (config.meanTorrentConfig.app.setDefaultValueOnIndex) {
var httpTransport = 'http://';
if (config.secure && config.secure.ssl === true) {
httpTransport = 'https://';
}
var baseUrl = httpTransport + req.headers.host;
cfg.app.domain = baseUrl;
}
if (!cfg.announce.abs) {
cfg.announce.abs = cfg.announce.url;
}
cfg.announce.url = cfg.app.domain + cfg.announce.abs;
return cfg;
}

View File

@@ -20,6 +20,7 @@ var traceConfig = config.meanTorrentConfig.trace;
var mtDebug = require(path.resolve('./config/lib/debug'));
var inviteConfig = config.meanTorrentConfig.invite;
var scoreConfig = config.meanTorrentConfig.score;
var appConfig = config.meanTorrentConfig.app;
/**
* A Validation function for local strategy email
@@ -202,16 +203,11 @@ exports.update = function (req, res) {
return res.status(422).send({message: 'EMAIL_ALREADY_EXIST'});
} else {
//send invitation mail
var httpTransport = 'http://';
if (config.secure && config.secure.ssl === true) {
httpTransport = 'https://';
}
var baseUrl = httpTransport + req.headers.host;
res.render(path.resolve('modules/invitations/server/templates/invite-sign-up-email'), {
to_email: req.query.to_email,
name: req.user.displayName,
appName: config.app.title,
url: baseUrl + '/api/auth/invite/' + invitation.token,
url: appConfig.domain + '/api/auth/invite/' + invitation.token,
hours: config.meanTorrentConfig.invite.expires / (60 * 60 * 1000)
}, function (err, emailHTML) {
if (err) {
@@ -321,16 +317,11 @@ exports.sendOfficial = function (req, res) {
});
//send invitation mail
var httpTransport = 'http://';
if (config.secure && config.secure.ssl === true) {
httpTransport = 'https://';
}
var baseUrl = httpTransport + req.headers.host;
res.render(path.resolve('modules/invitations/server/templates/invite-sign-up-email'), {
to_email: req.body.email,
name: req.user.displayName,
appName: config.app.title,
url: baseUrl + '/api/auth/invite/' + invitation.token,
url: appConfig.domain + '/api/auth/invite/' + invitation.token,
hours: config.meanTorrentConfig.invite.expires / (60 * 60 * 1000)
}, function (err, emailHTML) {
if (err) {

View File

@@ -15,6 +15,7 @@ var path = require('path'),
var smtpTransport = nodemailer.createTransport(config.mailer.options);
var mtConfig = config.meanTorrentConfig;
var appConfig = config.meanTorrentConfig.app;
// URLs for which user can't be redirected on signin
var noReturnUrls = [
@@ -67,16 +68,11 @@ exports.signup = function (req, res) {
user.salt = undefined;
/* send an account active mail */
var httpTransport = 'http://';
if (config.secure && config.secure.ssl === true) {
httpTransport = 'https://';
}
var baseUrl = httpTransport + req.headers.host;
res.render(path.resolve('modules/users/server/templates/sign-up-active-email'), {
name: user.displayName,
appName: config.app.title,
hours: mtConfig.sign.signUpActiveTokenExpires / (60 * 60 * 1000),
url: baseUrl + '/api/auth/active/' + user.signUpActiveToken
url: appConfig.domain + '/api/auth/active/' + user.signUpActiveToken
}, function (err, emailHTML) {
if (err) {
return res.status(400).send({

View File

@@ -18,6 +18,7 @@ var path = require('path'),
var smtpTransport = nodemailer.createTransport(config.mailer.options);
var traceConfig = config.meanTorrentConfig.trace;
var passwordConfig = config.meanTorrentConfig.password;
var appConfig = config.meanTorrentConfig.app;
/**
* Forgot for reset password (forgot POST)
@@ -76,16 +77,10 @@ exports.forgot = function (req, res, next) {
}
},
function (token, user, done) {
var httpTransport = 'http://';
if (config.secure && config.secure.ssl === true) {
httpTransport = 'https://';
}
var baseUrl = httpTransport + req.headers.host;
res.render(path.resolve('modules/users/server/templates/reset-password-email'), {
name: user.displayName,
appName: config.app.title,
url: baseUrl + '/api/auth/reset/' + token
url: appConfig.domain + '/api/auth/reset/' + token
}, function (err, emailHTML) {
done(err, emailHTML, user);
});