mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +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
|
password: password
|
||||||
}).then(function (user) {
|
}).then(function (user) {
|
||||||
|
|
||||||
ghost.mail.sendWelcomeMessage({email: user.attributes.email_address});
|
|
||||||
|
|
||||||
if (req.session.user === undefined) {
|
if (req.session.user === undefined) {
|
||||||
req.session.user = user.id;
|
req.session.user = user.id;
|
||||||
}
|
}
|
||||||
@ -177,39 +175,37 @@ adminControllers = {
|
|||||||
subject: 'Your new password',
|
subject: 'Your new password',
|
||||||
html: "<p><strong>Hello!</strong></p>" +
|
html: "<p><strong>Hello!</strong></p>" +
|
||||||
"<p>You've reset your password. Here's the new one: " + user.newPassword + "</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);
|
return ghost.mail.send(message);
|
||||||
// let's only add the notification once
|
}).then(function success() {
|
||||||
if (!_.contains(_.pluck(ghost.notifications, 'id'), 'successresetpw')) {
|
var notification = {
|
||||||
ghost.notifications.push(notification);
|
type: 'success',
|
||||||
}
|
message: 'Your password was changed successfully. Check your email for details.',
|
||||||
|
status: 'passive',
|
||||||
|
id: 'successresetpw'
|
||||||
|
};
|
||||||
|
|
||||||
res.json(200, {redirect: '/ghost/login/'});
|
return api.notifications.add(notification).then(function () {
|
||||||
}, function (error) {
|
res.json(200, {redirect: '/ghost/signin/'});
|
||||||
|
});
|
||||||
|
|
||||||
|
}, function failure(error) {
|
||||||
res.json(401, {error: error.message});
|
res.json(401, {error: error.message});
|
||||||
});
|
}).otherwise(errors.logAndThrowError);
|
||||||
},
|
},
|
||||||
'logout': function (req, res) {
|
'logout': function (req, res) {
|
||||||
delete req.session.user;
|
delete req.session.user;
|
||||||
var msg = {
|
var notification = {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: 'You were successfully signed out',
|
message: 'You were successfully signed out',
|
||||||
status: 'passive',
|
status: 'passive',
|
||||||
id: 'successlogout'
|
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) {
|
'index': function (req, res) {
|
||||||
res.render('dashboard', {
|
res.render('dashboard', {
|
||||||
|
@ -90,15 +90,14 @@ GhostMailer.prototype.emailDisabled = function () {
|
|||||||
// Sends an e-mail message enforcing `to` (blog owner) and `from` fields
|
// Sends an e-mail message enforcing `to` (blog owner) and `from` fields
|
||||||
GhostMailer.prototype.send = function (message) {
|
GhostMailer.prototype.send = function (message) {
|
||||||
if (!this.transport) {
|
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)) {
|
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(),
|
var from = 'ghost-mailer@' + url.parse(this.ghost.config().env[process.env.NODE_ENV].url).hostname,
|
||||||
from = 'ghost-mailer@' + url.parse(settings.url).hostname,
|
to = message.to || this.ghost.settings().email,
|
||||||
to = message.to || settings.email,
|
|
||||||
sendMail = nodefn.lift(this.transport.sendMail.bind(this.transport));
|
sendMail = nodefn.lift(this.transport.sendMail.bind(this.transport));
|
||||||
|
|
||||||
message = _.extend(message, {
|
message = _.extend(message, {
|
||||||
@ -107,20 +106,10 @@ GhostMailer.prototype.send = function (message) {
|
|||||||
generateTextFromHTML: true
|
generateTextFromHTML: true
|
||||||
});
|
});
|
||||||
|
|
||||||
return sendMail(message);
|
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');
|
||||||
GhostMailer.prototype.sendWelcomeMessage = function (opts) {
|
return when.reject(new Error(error));
|
||||||
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>"
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user