Email translations
This commit is contained in:
parent
952431d296
commit
6c8fa91f64
30 changed files with 1844 additions and 107 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
import i18n from 'i18next';
|
||||
import { getFileNameOfLang } from '/imports/api/Utility/server/files.js';
|
||||
import getPrivateFile from '../../../modules/server/get-private-file';
|
||||
import templateToHTML from '../../../modules/server/handlebars-email-to-html';
|
||||
import templateToText from '../../../modules/server/handlebars-email-to-text';
|
||||
|
||||
const name = '¡Tod@s contra el Fuego!';
|
||||
const name = i18n.t('AppName');
|
||||
const email = '<noreply@comunes.org>';
|
||||
const from = `${name} ${email}`;
|
||||
const emailTemplates = Accounts.emailTemplates;
|
||||
|
|
@ -17,7 +19,7 @@ emailTemplates.verifyEmail = {
|
|||
return `[${name}] Verify Your Email Address`;
|
||||
},
|
||||
html(user, url) {
|
||||
return templateToHTML(getPrivateFile('email-templates/verify-email.html'), {
|
||||
return templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', 'verify-email', 'html', user.lang)), {
|
||||
applicationName: name,
|
||||
firstName: user.profile.name.first,
|
||||
verifyUrl: url.replace('#/', '')
|
||||
|
|
@ -26,12 +28,12 @@ emailTemplates.verifyEmail = {
|
|||
text(user, url) {
|
||||
const urlWithoutHash = url.replace('#/', '');
|
||||
if (Meteor.isDevelopment) console.info(`Verify Email Link: ${urlWithoutHash}`); // eslint-disable-line
|
||||
return templateToText(getPrivateFile('email-templates/verify-email.txt'), {
|
||||
return templateToText(getPrivateFile(getFileNameOfLang('email-templates', 'verify-email', 'txt', user.lang)), {
|
||||
applicationName: name,
|
||||
firstName: user.profile.name.first,
|
||||
verifyUrl: urlWithoutHash,
|
||||
verifyUrl: urlWithoutHash
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
emailTemplates.resetPassword = {
|
||||
|
|
@ -39,21 +41,21 @@ emailTemplates.resetPassword = {
|
|||
return `[${name}] Reset Your Password`;
|
||||
},
|
||||
html(user, url) {
|
||||
return templateToHTML(getPrivateFile('email-templates/reset-password.html'), {
|
||||
return templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', 'reset-password', 'html', user.lang)), {
|
||||
firstName: user.profile.name.first,
|
||||
applicationName: name,
|
||||
emailAddress: user.emails[0].address,
|
||||
resetUrl: url.replace('#/', ''),
|
||||
resetUrl: url.replace('#/', '')
|
||||
});
|
||||
},
|
||||
text(user, url) {
|
||||
const urlWithoutHash = url.replace('#/', '');
|
||||
if (Meteor.isDevelopment) console.info(`Reset Password Link: ${urlWithoutHash}`); // eslint-disable-line
|
||||
return templateToText(getPrivateFile('email-templates/reset-password.txt'), {
|
||||
return templateToText(getPrivateFile(getFileNameOfLang('email-templates', 'reset-password', 'txt', user.lang)), {
|
||||
firstName: user.profile.name.first,
|
||||
applicationName: name,
|
||||
emailAddress: user.emails[0].address,
|
||||
resetUrl: urlWithoutHash,
|
||||
resetUrl: urlWithoutHash
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,15 @@ import sendWelcomeEmail from '../../../api/Users/server/send-welcome-email';
|
|||
|
||||
Accounts.onCreateUser((options, user) => {
|
||||
const userToCreate = user;
|
||||
if (options.profile) userToCreate.profile = options.profile;
|
||||
sendWelcomeEmail(options, user);
|
||||
console.log(JSON.stringify(user));
|
||||
console.log(JSON.stringify(options));
|
||||
if (options.profile) {
|
||||
userToCreate.profile = options.profile;
|
||||
userToCreate.lang = options.profile.lang;
|
||||
delete options.profile.lang;
|
||||
} else {
|
||||
// TODO others (google, etc) ?
|
||||
}
|
||||
sendWelcomeEmail(options, userToCreate);
|
||||
return userToCreate;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import { Meteor } from 'meteor/meteor';
|
|||
import moment from 'moment';
|
||||
import { dateLongFormat } from '/imports/api/Common/dates';
|
||||
import Notifications from '/imports/api/Notifications/Notifications';
|
||||
import sendMail from '/imports/startup/server/email';
|
||||
import { hr } from '/imports/startup/server/email';
|
||||
// import sendMail from '/imports/startup/server/email';
|
||||
import sendEmail from '/imports/modules/server/send-email';
|
||||
// import { hr } from '/imports/startup/server/email';
|
||||
import getOAuthProfile from '/imports/modules/get-oauth-profile';
|
||||
import image from 'google-maps-image-api-url';
|
||||
import { trim } from '/imports/ui/components/NotificationsObserver/util.js';
|
||||
|
|
@ -40,9 +41,10 @@ Meteor.startup(() => {
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
function imgEl(lat, lng) {
|
||||
return `<img src="${imgUrl(lat, lng)}" width="640" height="480"/>`;
|
||||
}
|
||||
} */
|
||||
|
||||
function process(notif) {
|
||||
if (notif.type === 'web' && !notif.emailNotified) {
|
||||
|
|
@ -58,31 +60,41 @@ Meteor.startup(() => {
|
|||
const emailAddress = OAuthProfile ? OAuthProfile.email :
|
||||
user && user.emails[0] && user.emails[0].verified ? user.emails[0].address : null;
|
||||
if (emailAddress) {
|
||||
const img = imgEl(notif.geo.coordinates[1], notif.geo.coordinates[0]);
|
||||
const img = imgUrl(notif.geo.coordinates[1], notif.geo.coordinates[0]);
|
||||
// const url = imgUrl(notif.geo.coordinates[1], notif.geo.coordinates[0]);
|
||||
const fireUrl = `${Meteor.absoluteUrl('fire/')}${notif.sealed}`;
|
||||
const fireHtmlUrl = `<a href="${fireUrl}">${i18n.t('Más información sobre este fuego')}</a>`;
|
||||
// const fireHtmlUrl = `<a href="${fireUrl}">${i18n.t('Más información sobre este fuego')}</a>`;
|
||||
// TODO get _id of fire
|
||||
const fireTextUrl = `${i18n.t('Más información sobre este fuego')}:\n${fireUrl}`;
|
||||
// const fireTextUrl = `${i18n.t('Más información sobre este fuego')}:\n${fireUrl}`;
|
||||
// FIXME use our map as url and static map as img
|
||||
moment.locale(user.lang);
|
||||
// moment user tz ?
|
||||
const message = `${trim(notif.content)} (${i18n.t('fireDetectedAt', { when: dateLongFormat(notif.when) })}).`;
|
||||
|
||||
// TODO unsubscribe link
|
||||
// TODO Address
|
||||
// TODO Comunes Address
|
||||
|
||||
const emailOpts = {
|
||||
to: emailAddress,
|
||||
userName: firstName,
|
||||
sendAt: new Date(),
|
||||
// userName: firstName,
|
||||
// sendAt: new Date(),
|
||||
subject: truncate.apply(message, [50, true]),
|
||||
text: `${message}\n\n${fireTextUrl}\n\n`,
|
||||
template: '<body><h2>{{appName}}</h2>{{{html}}}</body>',
|
||||
appName: i18n.t('AppName'),
|
||||
html: `<p>${message}</p><p>${fireHtmlUrl}</p>${hr}<p>${img}</p>`
|
||||
// text: `${message}\n\n${fireTextUrl}\n\n`,
|
||||
// template: '<body><h2>{{appName}}</h2>{{{html}}}</body>',
|
||||
lang: user.lang,
|
||||
template: 'new-fire',
|
||||
templateVars: {
|
||||
applicationName: i18n.t('AppName'),
|
||||
firstName,
|
||||
message,
|
||||
fireUrl,
|
||||
img,
|
||||
subsUrl: Meteor.absoluteUrl('subscriptions')
|
||||
}
|
||||
};
|
||||
sendMail(emailOpts, true);
|
||||
sendEmail(emailOpts).catch((error) => {
|
||||
throw new Meteor.Error('500', `${error}`);
|
||||
});
|
||||
// sendMail(emailOpts, true);
|
||||
Notifications.update(notif._id, { $set: { emailNotified: true, emailNotifiedAt: new Date() } });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue