diff options
-rw-r--r-- | config/accounts.js | 7 | ||||
-rw-r--r-- | models/settings.js | 19 | ||||
-rw-r--r-- | models/users.js | 36 | ||||
-rw-r--r-- | server/notifications/email.js | 20 |
4 files changed, 47 insertions, 35 deletions
diff --git a/config/accounts.js b/config/accounts.js index e7faa4cd..279325fb 100644 --- a/config/accounts.js +++ b/config/accounts.js @@ -16,12 +16,17 @@ AccountsTemplates.addFields([{ template: 'invitationCode', }]); +let sendVerificationEmail = false; +if (process.env.MAIL_URL) { + sendVerificationEmail = true; +} + AccountsTemplates.configure({ defaultLayout: 'userFormsLayout', defaultContentRegion: 'content', confirmPassword: false, enablePasswordChange: true, - sendVerificationEmail: true, + sendVerificationEmail, showForgotPasswordLink: true, onLogoutHook() { const homePage = 'home'; diff --git a/models/settings.js b/models/settings.js index 29b5f97c..0c2da4d3 100644 --- a/models/settings.js +++ b/models/settings.js @@ -35,6 +35,9 @@ Settings.attachSchema(new SimpleSchema({ })); Settings.helpers({ mailUrl () { + if (!this.mailServer.host) { + return null; + } if (!this.mailServer.username && !this.mailServer.password) { return `smtp://${this.mailServer.host}:${this.mailServer.port}/`; } @@ -69,7 +72,7 @@ if (Meteor.isServer) { }); Settings.after.update((userId, doc, fieldNames) => { // assign new values to mail-from & MAIL_URL in environment - if (_.contains(fieldNames, 'mailServer')) { + if (_.contains(fieldNames, 'mailServer') && _.contains(fieldNames, 'host')) { if (!doc.mailServer.username && !doc.mailServer.password) { process.env.MAIL_URL = `smtp://${doc.mailServer.host}:${doc.mailServer.port}/`; } else { @@ -97,12 +100,14 @@ if (Meteor.isServer) { url: FlowRouter.url('sign-up'), }; const lang = author.getLanguage(); - Email.send({ - to: icode.email, - from: Accounts.emailTemplates.from, - subject: TAPi18n.__('email-invite-register-subject', params, lang), - text: TAPi18n.__('email-invite-register-text', params, lang), - }); + if (Settings.findOne().mailUrl()) { + Email.send({ + to: icode.email, + from: Accounts.emailTemplates.from, + subject: TAPi18n.__('email-invite-register-subject', params, lang), + text: TAPi18n.__('email-invite-register-text', params, lang), + }); + } } catch (e) { InvitationCodes.remove(_id); throw new Meteor.Error('email-fail', e.message); diff --git a/models/users.js b/models/users.js index cdc4d9dc..f944d7b1 100644 --- a/models/users.js +++ b/models/users.js @@ -373,24 +373,25 @@ if (Meteor.isServer) { board.addMember(user._id); user.addInvite(boardId); - try { - const params = { - user: user.username, - inviter: inviter.username, - board: board.title, - url: board.absoluteUrl(), - }; - const lang = user.getLanguage(); - Email.send({ - to: user.emails[0].address.toLowerCase(), - from: Accounts.emailTemplates.from, - subject: TAPi18n.__('email-invite-subject', params, lang), - text: TAPi18n.__('email-invite-text', params, lang), - }); - } catch (e) { - throw new Meteor.Error('email-fail', e.message); + if (Settings.findOne().mailUrl()) { + try { + const params = { + user: user.username, + inviter: inviter.username, + board: board.title, + url: board.absoluteUrl(), + }; + const lang = user.getLanguage(); + Email.send({ + to: user.emails[0].address.toLowerCase(), + from: Accounts.emailTemplates.from, + subject: TAPi18n.__('email-invite-subject', params, lang), + text: TAPi18n.__('email-invite-text', params, lang), + }); + } catch (e) { + throw new Meteor.Error('email-fail', e.message); + } } - return { username: user.username, email: user.emails[0].address }; }, }); @@ -510,4 +511,3 @@ if (Meteor.isServer) { } }); } - diff --git a/server/notifications/email.js b/server/notifications/email.js index 2af6381e..cee874d9 100644 --- a/server/notifications/email.js +++ b/server/notifications/email.js @@ -26,15 +26,17 @@ Meteor.startup(() => { const text = texts.join('\n\n'); user.clearEmailBuffer(); - try { - Email.send({ - to: user.emails[0].address.toLowerCase(), - from: Accounts.emailTemplates.from, - subject: TAPi18n.__('act-activity-notify', {}, user.getLanguage()), - text, - }); - } catch (e) { - return; + if (Settings.findOne().mailUrl()) { + try { + Email.send({ + to: user.emails[0].address.toLowerCase(), + from: Accounts.emailTemplates.from, + subject: TAPi18n.__('act-activity-notify', {}, user.getLanguage()), + text, + }); + } catch (e) { + return; + } } }, 30000); }); |