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
This commit is contained in:
Sebastian Gierlinger 2014-07-13 20:36:27 +02:00
parent 707d0039cc
commit db5e02da2b
2 changed files with 11 additions and 4 deletions

View File

@ -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));
});
}

View File

@ -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);
});