Skip to content

Commit

Permalink
refactored test email API call
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Callens committed Mar 1, 2015
1 parent 4823c47 commit 4263025
Showing 1 changed file with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,44 @@
*/

module.exports = function(pb) {

//pb dependencies
var util = pb.util;

/**
* Resends an account verification email
*/
function SendTestEmail(){}
util.inherits(SendTestEmail, pb.FormController);
util.inherits(SendTestEmail, pb.BaseController);

SendTestEmail.prototype.onPostParamsRetrieved = function(post, cb) {
SendTestEmail.prototype.render = function(cb) {
var self = this;

var message = this.hasRequiredParams(post, this.getRequiredFields());
if(message) {
cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, message)});
return;
}

var options = {
to: post.email,
subject: 'Test email from PencilBlue',
layout: 'This is a successful test email from the PencilBlue system.',
};
var emailService = new pb.EmailService();
emailService.sendFromLayout(options, function(err, response) {
if(err) {
cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, JSON.stringify(err))});
this.getJSONPostParams(function(err, post) {
var message = self.hasRequiredParams(post, self.getRequiredFields());
if(message) {
cb({
code: 400,
content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, message)
});
return;
}
cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, 'email successfully sent')});

var options = {
to: post.email,
subject: 'Test email from PencilBlue',
layout: 'This is a successful test email from the PencilBlue system.',
};
pb.email.sendFromLayout(options, function(err, response) {
if(err) {
cb({
code: 500,
content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, JSON.stringify(err))
});
return;
}
cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, 'email successfully sent')});
});
});
};

Expand Down

0 comments on commit 4263025

Please sign in to comment.