0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Merge pull request #3444 from sebgie/fix-invitations

Fix Invitations
This commit is contained in:
Hannah Wolfe 2014-07-30 13:40:23 +01:00
commit ecc8c96c03
4 changed files with 54 additions and 45 deletions

View file

@ -56,8 +56,7 @@ var InviteNewUserController = Ember.Controller.extend({
// but the user's status in the response object will be 'invited-pending'. // but the user's status in the response object will be 'invited-pending'.
if (newUser.get('status') === 'invited-pending') { if (newUser.get('status') === 'invited-pending') {
self.notifications.showWarn('Invitation email was not sent. Please try resending.'); self.notifications.showWarn('Invitation email was not sent. Please try resending.');
} } else {
else {
self.notifications.showSuccess(notificationText, false); self.notifications.showSuccess(notificationText, false);
} }
}).catch(function (errors) { }).catch(function (errors) {

View file

@ -66,10 +66,16 @@ var SettingsUserController = Ember.ObjectController.extend({
resend: function () { resend: function () {
var self = this; var self = this;
this.get('model').resendInvite().then(function () { this.get('model').resendInvite().then(function (result) {
self.get('model').set('status', 'invited');
var notificationText = 'Invitation resent! (' + self.get('email') + ')'; var notificationText = 'Invitation resent! (' + self.get('email') + ')';
// If sending the invitation email fails, the API will still return a status of 201
// but the user's status in the response object will be 'invited-pending'.
if (result.users[0].status === 'invited-pending') {
self.notifications.showWarn('Invitation email was not sent. Please try resending.');
} else {
self.get('model').set('status', result.users[0].status);
self.notifications.showSuccess(notificationText, false); self.notifications.showSuccess(notificationText, false);
}
}).catch(function (error) { }).catch(function (error) {
self.notifications.closePassive(); self.notifications.closePassive();
self.notifications.showAPIError(error); self.notifications.showAPIError(error);

View file

@ -1,7 +1,7 @@
// # Mail API // # Mail API
// API for sending Mail // API for sending Mail
var when = require('when'), var _ = require('lodash'),
_ = require('lodash'), when = require('when'),
config = require('../config'), config = require('../config'),
canThis = require('../permissions').canThis, canThis = require('../permissions').canThis,
errors = require('../errors'), errors = require('../errors'),
@ -105,7 +105,8 @@ mail = {
//generate a plain-text version of the same email //generate a plain-text version of the same email
textContent = htmlToText.fromString(htmlContent); textContent = htmlToText.fromString(htmlContent);
resolve({ html: htmlContent, resolve({
html: htmlContent,
text: textContent text: textContent
}); });

View file

@ -132,7 +132,8 @@ users = {
add: function add(object, options) { add: function add(object, options) {
var newUser, var newUser,
user, user,
roleId; roleId,
emailData;
return canThis(options.context).add.user(object).then(function () { return canThis(options.context).add.user(object).then(function () {
return utils.checkObject(object, docName).then(function (checkedUserData) { return utils.checkObject(object, docName).then(function (checkedUserData) {
@ -182,11 +183,12 @@ users = {
dbHash = response.settings[0].value; dbHash = response.settings[0].value;
return dataProvider.User.generateResetToken(user.email, expires, dbHash); return dataProvider.User.generateResetToken(user.email, expires, dbHash);
}).then(function (resetToken) { }).then(function (resetToken) {
when.join(users.read({'id': user.created_by}), settings.read({'key': 'title'})).then(function (values) { return when.join(users.read({'id': user.created_by}), settings.read({'key': 'title'})).then(function (values) {
var invitedBy = values[0].users[0], var invitedBy = values[0].users[0],
blogTitle = values[1].settings[0].value, blogTitle = values[1].settings[0].value,
baseUrl = config.forceAdminSSL ? (config.urlSSL || config.url) : config.url, baseUrl = config.forceAdminSSL ? (config.urlSSL || config.url) : config.url,
resetUrl = baseUrl.replace(/\/$/, '') + '/ghost/signup/' + resetToken + '/', resetUrl = baseUrl.replace(/\/$/, '') + '/ghost/signup/' + resetToken + '/';
emailData = { emailData = {
blogName: blogTitle, blogName: blogTitle,
invitedByName: invitedBy.name, invitedByName: invitedBy.name,
@ -194,8 +196,8 @@ users = {
resetLink: resetUrl resetLink: resetUrl
}; };
mail.generateContent({data: emailData, template: 'invite-user'}).then(function (emailContent) { return mail.generateContent({data: emailData, template: 'invite-user'});
}).then(function (emailContent) {
var payload = { var payload = {
mail: [ mail: [
{ {
@ -212,9 +214,10 @@ users = {
return mail.send(payload, {context: {internal: true}}).then(function () { return mail.send(payload, {context: {internal: true}}).then(function () {
// If status was invited-pending and sending the invitation succeeded, set status to invited. // If status was invited-pending and sending the invitation succeeded, set status to invited.
if (user.status === 'invited-pending') { if (user.status === 'invited-pending') {
return dataProvider.User.edit({status: 'invited'}, {id: user.id}); return dataProvider.User.edit({status: 'invited'}, {id: user.id}).then(function (editedUser) {
} user = editedUser.toJSON();
}); });
}
}); });
}); });
}).then(function () { }).then(function () {