Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E-mail wrapper and product URL for easier migration to production #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ module.exports = {
subs: {
// text to include in emails and the sign up verification screen
productName: '[feathers-starter-react-redux-login-roles]',
productUrl: '[http://feathers-starter.feathersjs.com]',
senderName: '[Feathers Starter]',
productUrl: defer(finalConfig => {
let url = `http://${finalConfig.server.host}`;
if (`${finalConfig.server.port}` !== '80') {
url += `:${finalConfig.server.port}`;
}
return url;
}),
senderName: defer(finalConfig => `${finalConfig.authEmails.subs.productName} Verifier`),
fromEmail: '[Feathers Starter <[email protected]>]',
supportEmail: '[Starter Support <[email protected]>]',
copyrightYears: '2015-2016',
Expand Down
50 changes: 28 additions & 22 deletions server/helpers/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,58 @@ const email = require('config').authEmails;

debug('Required');

const sendEmail = (...lines) => {
for (const line of lines) {
console.log(line);
}
};

module.exports = function (action, user, params, cb) {
debug(`Send email type ${action}`);

switch (action) {
case 'send':
console.log('-- Sending email to verify new user\'s email addr');
console.log(`Dear ${user.username}, please click this link to verify your email addr.`);
console.log(` http://localhost:3030/user/verify/${user.verifyToken}`);
console.log(` This email is valid for the next ${email.expires.signUpEmailTokenTimeValidText}.`);
sendEmail(`Dear ${user.username}, please click this link to verify your email addr.`,
` ${email.subs.productUrl}/user/verify/${user.verifyToken}`,
` This email is valid for the next ${email.expires.signUpEmailTokenTimeValidText}.`);
return cb(null);
case 'resend':
console.log(`-- Resending email to ${user.email} to verify new user's email addr`);
console.log(`Dear ${user.username}, please click this link to verify your email addr.`);
console.log(` http://localhost:3030/user/verify/${user.verifyToken}`);
console.log(` This email is valid for the next ${email.expires.signUpEmailTokenTimeValidText}.`);
sendEmail(`Dear ${user.username}, please click this link to verify your email addr.`,
` ${email.subs.productUrl}/user/verify/${user.verifyToken}`,
` This email is valid for the next ${email.expires.signUpEmailTokenTimeValidText}.`);
return cb(null);
case 'verify':
console.log(`-- Sending email to ${user.email} to confirm they are verified.`);
console.log(`Dear ${user.username}, your email has been verified at ${email.subs.productName}.`);
console.log(` You can sign in at ${email.subs.productUrl}.`);
sendEmail(`Dear ${user.username}, your email has been verified at ${email.subs.productName}.`,
` You can sign in at ${email.subs.productUrl}.`);
return cb(null);
case 'forgot':
console.log(`-- Resending email to ${user.email} to reset password`);
console.log(`Dear ${user.username}, please click this link to reset your password.`);
console.log(` http://localhost:3030/user/forgot/${user.resetToken}`);
console.log(` This email is valid for the next ${email.expires.forgotPasswordEmailTokenTimeValidText}.`);
sendEmail(`Dear ${user.username}, please click this link to reset your password.`,
` ${email.subs.productUrl}/user/forgot/${user.resetToken}`,
` This email is valid for the next ${email.expires.forgotPasswordEmailTokenTimeValidText}.`);
return cb(null);
case 'reset':
console.log(`-- Sending email to ${user.email} to notify them of password change.`);
console.log(`Dear ${user.username}, your password at ${email.subs.productName} has been changed`);
console.log(' by password rest.');
console.log(` Please contact us at ${email.subs.supportEmail} if you did not initiate this change.`);
console.log(` You can sign in at ${email.subs.productUrl}.`);
sendEmail(`Dear ${user.username}, your password at ${email.subs.productName} has been changed`,
' by password reset.',
` Please contact us at ${email.subs.supportEmail} if you did not initiate this change.`,
` You can sign in at ${email.subs.productUrl}.`);
return cb(null);
case 'password':
console.log(`-- Sending email to ${user.email} to notify them of password change.`);
console.log(`Dear ${user.username}, your password at ${email.subs.productName} has been changed manually.`);
console.log(` Please contact us at ${email.subs.supportEmail} if you did not initiate this change.`);
console.log(` You can sign in at ${email.subs.productUrl}.`);
sendEmail(`Dear ${user.username}, your password at ${email.subs.productName} has been changed manually.`,
` Please contact us at ${email.subs.supportEmail} if you did not initiate this change.`,
` You can sign in at ${email.subs.productUrl}.`);
return cb(null);
case 'email':
console.log(`-- Sending email to ${user.email} to notify them of email change.`);
console.log(`Dear ${user.username}, your email address at ${email.subs.productName} is being`);
console.log(` changed from this address to ${user.newEmail}.`);
console.log(` Please contact us at ${email.subs.supportEmail} if you did not initiate this change.`);
console.log(` You can sign in at ${email.subs.productUrl}.`);
sendEmail(`Dear ${user.username}, your email address at ${email.subs.productName} is being`,
` changed from this address to ${user.newEmail}.`,
` Please contact us at ${email.subs.supportEmail} if you did not initiate this change.`,
` You can sign in at ${email.subs.productUrl}.`);
return cb(null);
default:
return cb(null);
Expand Down