66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
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');
|
|
|
|
ContactUsMessages.attachSchema(new SimpleSchema({
|
|
name: {
|
|
type: String,
|
|
label: "Name",
|
|
optional: false,
|
|
trim: false,
|
|
},
|
|
email: {
|
|
type: String,
|
|
label: "Email",
|
|
optional: false,
|
|
trim: false
|
|
},
|
|
message: {
|
|
type: String,
|
|
label: "Message",
|
|
optional: false,
|
|
trim: false
|
|
},
|
|
createdAt: {
|
|
type: Date,
|
|
label: "Created On",
|
|
optional: true
|
|
}
|
|
}));
|
|
|
|
if(Meteor.isServer) Meteor.publish('contactUsMessages', function() {
|
|
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
|
return ContactUsMessages.find({});
|
|
}
|
|
else throw new Meteor.Error(403, "Not authorized.");
|
|
});
|
|
|
|
if(Meteor.isServer) {
|
|
Meteor.methods({
|
|
submitContactForm: function(name, email, message) {
|
|
check(name, String);
|
|
check(email, String);
|
|
check(message, String);
|
|
|
|
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);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
export default ContactUsMessages;
|