fix(email): Error messages for updateEmail API

This commit is contained in:
Mrugesh Mohapatra
2017-04-24 13:06:17 +05:30
committed by Berkeley Martinez
parent 3f332fc1f0
commit d313ab68e4

View File

@ -15,6 +15,7 @@ const debug = debugFactory('fcc:user:remote');
const BROWNIEPOINTS_TIMEOUT = [1, 'hour']; const BROWNIEPOINTS_TIMEOUT = [1, 'hour'];
const isDev = process.env.NODE_ENV !== 'production'; const isDev = process.env.NODE_ENV !== 'production';
const devHost = process.env.HOST || 'localhost'; const devHost = process.env.HOST || 'localhost';
const emailSender = process.env.EMAIL_SENDER || 'team@freecodecamp.org';
const createEmailError = () => new Error( const createEmailError = () => new Error(
'Please check to make sure the email is a valid email address.' 'Please check to make sure the email is a valid email address.'
@ -595,8 +596,7 @@ module.exports = function(User) {
const mailOptions = { const mailOptions = {
type: 'email', type: 'email',
to: user.email, to: user.email,
from: isDev ? from: emailSender,
process.env.EMAIL_SENDER : 'team@freecodecamp.com',
subject: 'freeCodeCamp - Authentication Request!', subject: 'freeCodeCamp - Authentication Request!',
text: renderAuthEmail({ text: renderAuthEmail({
loginEmail, loginEmail,
@ -662,14 +662,14 @@ module.exports = function(User) {
} }
const minutesLeft = getWaitPeriod(this.emailVerifyTTL); const minutesLeft = getWaitPeriod(this.emailVerifyTTL);
if (ownEmail && minutesLeft) { if (ownEmail && minutesLeft > 0) {
const timeToWait = minutesLeft ? const timeToWait = minutesLeft ?
`${minutesLeft} minute${minutesLeft > 1 ? 's' : ''}` : `${minutesLeft} minute${minutesLeft > 1 ? 's' : ''}` :
'a few seconds'; 'a few seconds';
debug('request before wait time : ' + timeToWait); debug('request before wait time : ' + timeToWait);
return Observable.throw(new Error( return Observable.of(dedent`
`Please wait ${timeToWait} to resend email verification.` Please wait ${timeToWait} to resend an authentication link.
)); `);
} }
return Observable.fromPromise(User.doesExist(null, email)) return Observable.fromPromise(User.doesExist(null, email))
@ -697,8 +697,8 @@ module.exports = function(User) {
const mailOptions = { const mailOptions = {
type: 'email', type: 'email',
to: email, to: email,
from: 'team@freecodecamp.org', from: emailSender,
subject: 'Welcome to freeCodeCamp!', subject: 'freeCodeCamp - Email Update Requested',
protocol: isDev ? null : 'https', protocol: isDev ? null : 'https',
host: isDev ? devHost : 'freecodecamp.org', host: isDev ? devHost : 'freecodecamp.org',
port: isDev ? null : 443, port: isDev ? null : 443,