From db5e02da2bd2899bb71ed6b4557fa9177d80bbd5 Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Sun, 13 Jul 2014 20:36:27 +0200 Subject: [PATCH] Add status invited-pending for users no issue - added status invited-pending for invited users where sending the invitation email failed - removed console.log() from authentication.js --- core/server/api/authentication.js | 2 -- core/server/api/users.js | 13 +++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/server/api/authentication.js b/core/server/api/authentication.js index c27fe7e433..180f8dcac2 100644 --- a/core/server/api/authentication.js +++ b/core/server/api/authentication.js @@ -198,8 +198,6 @@ authentication = { }).then(function () { return when.resolve({ users: [setupUser]}); }).otherwise(function (error) { - console.log('error'); - console.log(error); return when.reject(new errors.UnauthorizedError(error.message)); }); } diff --git a/core/server/api/users.js b/core/server/api/users.js index 6420c750be..459a1b40a8 100644 --- a/core/server/api/users.js +++ b/core/server/api/users.js @@ -161,7 +161,7 @@ users = { return dataProvider.User.add(newUser, options); } else { // only invitations for already invited users are resent - if (foundUser.toJSON().status === 'invited') { + if (foundUser.get('status') === 'invited' || foundUser.get('status') === 'invited-pending') { return foundUser; } else { return when.reject(new errors.BadRequestError('User is already registered.')); @@ -192,12 +192,21 @@ users = { options: {} }] }; - return mail.send(payload); + return mail.send(payload).then(function () { + // If status was invited-pending and sending the invitation succeeded, set status to invited. + if (user.status === 'invited-pending') { + return dataProvider.User.edit({status: 'invited'}, {id: user.id}); + } + }); }).then(function () { return when.resolve({users: [user]}); }).otherwise(function (error) { if (error && error.type === 'EmailError') { error.message = 'Error sending email: ' + error.message + ' Please check your email settings and resend the invitation.'; + // If sending the invitation failed, set status to invited-pending + return dataProvider.User.edit({status: 'invited-pending'}, {id: user.id}).then(function () { + return when.reject(error); + }); } return when.reject(error); });