mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
Email errors & cleanup
closes #618 - don't send a welcome email. This appeared to be breaking tests. - make sure we handle errors from sending emails properly - use promises when adding notifications
This commit is contained in:
parent
6051573d5a
commit
21487aa802
@ -148,8 +148,6 @@ adminControllers = {
|
||||
password: password
|
||||
}).then(function (user) {
|
||||
|
||||
ghost.mail.sendWelcomeMessage({email: user.attributes.email_address});
|
||||
|
||||
if (req.session.user === undefined) {
|
||||
req.session.user = user.id;
|
||||
}
|
||||
@ -177,39 +175,37 @@ adminControllers = {
|
||||
subject: 'Your new password',
|
||||
html: "<p><strong>Hello!</strong></p>" +
|
||||
"<p>You've reset your password. Here's the new one: " + user.newPassword + "</p>"
|
||||
},
|
||||
notification = {
|
||||
type: 'success',
|
||||
message: 'Your password was changed successfully. Check your email for details.',
|
||||
status: 'passive',
|
||||
id: 'successresetpw'
|
||||
};
|
||||
|
||||
ghost.mail.send(message);
|
||||
// let's only add the notification once
|
||||
if (!_.contains(_.pluck(ghost.notifications, 'id'), 'successresetpw')) {
|
||||
ghost.notifications.push(notification);
|
||||
}
|
||||
return ghost.mail.send(message);
|
||||
}).then(function success() {
|
||||
var notification = {
|
||||
type: 'success',
|
||||
message: 'Your password was changed successfully. Check your email for details.',
|
||||
status: 'passive',
|
||||
id: 'successresetpw'
|
||||
};
|
||||
|
||||
res.json(200, {redirect: '/ghost/login/'});
|
||||
}, function (error) {
|
||||
return api.notifications.add(notification).then(function () {
|
||||
res.json(200, {redirect: '/ghost/signin/'});
|
||||
});
|
||||
|
||||
}, function failure(error) {
|
||||
res.json(401, {error: error.message});
|
||||
});
|
||||
}).otherwise(errors.logAndThrowError);
|
||||
},
|
||||
'logout': function (req, res) {
|
||||
delete req.session.user;
|
||||
var msg = {
|
||||
var notification = {
|
||||
type: 'success',
|
||||
message: 'You were successfully signed out',
|
||||
status: 'passive',
|
||||
id: 'successlogout'
|
||||
};
|
||||
// let's only add the notification once
|
||||
if (!_.contains(_.pluck(ghost.notifications, 'id'), 'successlogout')) {
|
||||
ghost.notifications.push(msg);
|
||||
}
|
||||
|
||||
res.redirect('/ghost/signin/');
|
||||
return api.notifications.add(notification).then(function () {
|
||||
res.redirect('/ghost/signin/');
|
||||
});
|
||||
},
|
||||
'index': function (req, res) {
|
||||
res.render('dashboard', {
|
||||
|
@ -90,15 +90,14 @@ GhostMailer.prototype.emailDisabled = function () {
|
||||
// Sends an e-mail message enforcing `to` (blog owner) and `from` fields
|
||||
GhostMailer.prototype.send = function (message) {
|
||||
if (!this.transport) {
|
||||
return when.reject(new Error('No e-mail transport configured.'));
|
||||
return when.reject(new Error('Email Error: No e-mail transport configured.'));
|
||||
}
|
||||
if (!(message && message.subject && message.html)) {
|
||||
return when.reject(new Error('Incomplete message data.'));
|
||||
return when.reject(new Error('Email Error: Incomplete message data.'));
|
||||
}
|
||||
|
||||
var settings = this.ghost.settings(),
|
||||
from = 'ghost-mailer@' + url.parse(settings.url).hostname,
|
||||
to = message.to || settings.email,
|
||||
var from = 'ghost-mailer@' + url.parse(this.ghost.config().env[process.env.NODE_ENV].url).hostname,
|
||||
to = message.to || this.ghost.settings().email,
|
||||
sendMail = nodefn.lift(this.transport.sendMail.bind(this.transport));
|
||||
|
||||
message = _.extend(message, {
|
||||
@ -107,20 +106,10 @@ GhostMailer.prototype.send = function (message) {
|
||||
generateTextFromHTML: true
|
||||
});
|
||||
|
||||
return sendMail(message);
|
||||
};
|
||||
|
||||
GhostMailer.prototype.sendWelcomeMessage = function (opts) {
|
||||
var adminURL = this.ghost.settings().url + "/ghost";
|
||||
|
||||
opts = opts || {};
|
||||
opts.email = opts.email || this.ghost.settings().email;
|
||||
return this.send({
|
||||
to: opts.email,
|
||||
subject: "Welcome to Ghost",
|
||||
html: "<p><strong>Hello!</strong></p>" +
|
||||
"<p>Welcome to the Ghost platform.</p>" +
|
||||
"<p>Your dashboard is ready at <a href=\"" + adminURL + "\">" + adminURL + "</a>"
|
||||
return sendMail(message).otherwise(function (error) {
|
||||
// Proxy the error message so we can add 'Email Error:' to the beginning to make it clearer.
|
||||
error = _.isString(error) ? 'Email Error:' + error : (_.isObject(error) ? 'Email Error: ' + error.message : 'Email Error: Unknown Email Error');
|
||||
return when.reject(new Error(error));
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user