Added settings and messages to manage sending web inquiries to one or more email addresses specified via the web management interface.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import { Email } from 'meteor/email';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let ContactUsMessages = new Mongo.Collection('ContactUsMessages');
|
||||
@@ -32,7 +33,10 @@ ContactUsMessages.attachSchema(new SimpleSchema({
|
||||
}));
|
||||
|
||||
if(Meteor.isServer) Meteor.publish('contactUsMessages', function() {
|
||||
return ContactUsMessages.find({});
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
return ContactUsMessages.find({});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
});
|
||||
|
||||
if(Meteor.isServer) {
|
||||
@@ -42,10 +46,18 @@ if(Meteor.isServer) {
|
||||
check(email, String);
|
||||
check(message, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
ContactUsMessages.insert({name, email, message, createdAt: new Date()});
|
||||
ContactUsMessages.insert({name, email, message, createdAt: new Date()});
|
||||
|
||||
try {
|
||||
let settings = Meteor.collections.Settings.findOne();
|
||||
|
||||
if(settings && settings.forwardEmailsTo && settings.forwardEmailsTo.length > 0) {
|
||||
Email.send({to: settings.forwardEmailsTo, from: "Do Not Reply <no-reply@andersonvalleyeducation.org>", subject: "Contact Us Message", text: "Email: " + email + "\n\n" + message});
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
console.log(err);
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user