summaryrefslogtreecommitdiffstats
path: root/models/settings.js
diff options
context:
space:
mode:
authorlkisme <lkisme@me.com>2017-03-09 23:29:48 +0800
committerlkisme <lkisme@me.com>2017-03-09 23:29:48 +0800
commit72c3651be4365d3b903d694e55a3ea373d260709 (patch)
tree2b9386257d2ecc9e4c917231a835ed20d1f65851 /models/settings.js
parenta64e9af1d358aceabb066b5af771b3b4b33f2a12 (diff)
downloadwekan-72c3651be4365d3b903d694e55a3ea373d260709.tar.gz
wekan-72c3651be4365d3b903d694e55a3ea373d260709.tar.bz2
wekan-72c3651be4365d3b903d694e55a3ea373d260709.zip
Set mail-from to environment immediately after changed,
allow user set a blank username&password pair in SMTP setting.
Diffstat (limited to 'models/settings.js')
-rw-r--r--models/settings.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/models/settings.js b/models/settings.js
index b9ff1b37..0e6ab762 100644
--- a/models/settings.js
+++ b/models/settings.js
@@ -35,8 +35,10 @@ Settings.attachSchema(new SimpleSchema({
}));
Settings.helpers({
mailUrl () {
- const mailUrl = `smtp://${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`;
- return mailUrl;
+ if (!this.mailServer.username && !this.mailServer.password) {
+ return `smtp://${this.mailServer.host}:${this.mailServer.port}/`;
+ }
+ return `smtp://${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`;
},
});
Settings.allow({
@@ -65,6 +67,17 @@ if (Meteor.isServer) {
process.env.MAIL_URL = newSetting.mailUrl();
Accounts.emailTemplates.from = newSetting.mailServer.from;
});
+ Settings.after.update((userId, doc, fieldNames) => {
+ // assign new values to mail-from & MAIL_URL in environment
+ if (_.contains(fieldNames, 'mailServer')) {
+ if (!doc.mailServer.username && !doc.mailServer.password) {
+ process.env.MAIL_URL = `smtp://${doc.mailServer.host}:${doc.mailServer.port}/`;
+ } else {
+ process.env.MAIL_URL = `smtp://${doc.mailServer.username}:${doc.mailServer.password}@${doc.mailServer.host}:${doc.mailServer.port}/`;
+ }
+ Accounts.emailTemplates.from = doc.mailServer.from;
+ }
+ });
function getRandomNum (min, max) {
const range = max - min;
@@ -107,7 +120,11 @@ if (Meteor.isServer) {
if (email && SimpleSchema.RegEx.Email.test(email)) {
const code = getRandomNum(100000, 999999);
InvitationCodes.insert({code, email, boardsToBeInvited: boards, createdAt: new Date(), authorId: Meteor.userId()}, function(err, _id){
- if(!err && _id) sendInvitationEmail(_id);
+ if (!err && _id) {
+ sendInvitationEmail(_id);
+ } else {
+ throw new Meteor.Error('invitation-generated-fail', err.message);
+ }
});
}
});