mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
add tests for emails (wip) and encryption, misc fixes
This commit is contained in:
@@ -30,14 +30,18 @@ export function send (mailData) {
|
|||||||
.catch((error) => logger.error(error));
|
.catch((error) => logger.error(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserInfo (user, fields) {
|
export function getUserInfo (user, fields = []) {
|
||||||
let info = {};
|
let info = {};
|
||||||
|
|
||||||
if (fields.indexOf('name') !== -1) {
|
if (fields.indexOf('name') !== -1) {
|
||||||
if (user.auth.local) {
|
info.name = user.profile && user.profile.name;
|
||||||
info.name = user.profile.name || user.auth.local.username;
|
|
||||||
} else if (user.auth.facebook) {
|
if (!info.name) {
|
||||||
info.name = user.profile.name || user.auth.facebook.displayName || user.auth.facebook.username;
|
if (user.auth.local && user.auth.local.username) {
|
||||||
|
info.name = user.auth.local.username;
|
||||||
|
} else if (user.auth.facebook) {
|
||||||
|
info.name = user.auth.facebook.displayName || user.auth.facebook.username;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,14 +58,16 @@ export function getUserInfo (user, fields) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fields.indexOf('canSend') !== -1) {
|
if (fields.indexOf('canSend') !== -1) {
|
||||||
info.canSend = user.preferences.emailNotifications.unsubscribeFromAll !== true;
|
if (user.preferences && user.preferences.emailNotifications) {
|
||||||
|
info.canSend = user.preferences.emailNotifications.unsubscribeFromAll !== true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a transactional email using Mandrill through the external email server
|
// Send a transactional email using Mandrill through the external email server
|
||||||
export function txnEmail (mailingInfoArray, emailType, variables, personalVariables) {
|
export function sendTxn (mailingInfoArray, emailType, variables, personalVariables) {
|
||||||
mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray];
|
mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray];
|
||||||
|
|
||||||
variables = [
|
variables = [
|
||||||
@@ -127,9 +133,8 @@ export function txnEmail (mailingInfoArray, emailType, variables, personalVariab
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (IS_PROD && mailingInfoArray.length > 0) {
|
if (IS_PROD && mailingInfoArray.length > 0) {
|
||||||
request({
|
request.post({
|
||||||
url: `${EMAIL_SERVER.url}/job`,
|
url: `${EMAIL_SERVER.url}/job`,
|
||||||
method: 'POST',
|
|
||||||
auth: {
|
auth: {
|
||||||
user: EMAIL_SERVER.auth.user,
|
user: EMAIL_SERVER.auth.user,
|
||||||
pass: EMAIL_SERVER.auth.password,
|
pass: EMAIL_SERVER.auth.password,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
} from 'crypto';
|
} from 'crypto';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
|
|
||||||
|
// TODO check this is secure
|
||||||
const algorithm = 'aes-256-ctr';
|
const algorithm = 'aes-256-ctr';
|
||||||
const SESSION_SECRET = nconf.get('SESSION_SECRET');
|
const SESSION_SECRET = nconf.get('SESSION_SECRET');
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ if (IS_PROD) {
|
|||||||
// log errors to console too
|
// log errors to console too
|
||||||
} else {
|
} else {
|
||||||
logger
|
logger
|
||||||
.add(winston.transports.Console);
|
.add(winston.transports.Console, {
|
||||||
|
colorize: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default logger;
|
export default logger;
|
||||||
|
|||||||
Reference in New Issue
Block a user