示例#1
0
        private void AddInvitedUserToOrganization(string token, User user)
        {
            if (user == null)
            {
                return;
            }

            Invite       invite;
            Organization organization = _organizationRepository.GetByInviteToken(token, out invite);

            if (organization == null)
            {
                return;
            }

            if (!user.IsEmailAddressVerified && String.Equals(user.EmailAddress, invite.EmailAddress, StringComparison.OrdinalIgnoreCase))
            {
                user.IsEmailAddressVerified = true;
                _userRepository.Save(user);
            }

            if (!_billingManager.CanAddUser(organization))
            {
                ModelState.AddModelError(String.Empty, "Please upgrade your plan to add an additional user.");
                return;
            }

            user.OrganizationIds.Add(organization.Id);
            _userRepository.Save(user);

            organization.Invites.Remove(invite);
            _organizationRepository.Save(organization);
        }
        public async Task <IHttpActionResult> AddUser(string id, string email)
        {
            if (String.IsNullOrEmpty(id) || !CanAccessOrganization(id) || String.IsNullOrEmpty(email))
            {
                return(BadRequest());
            }

            Organization organization = _repository.GetById(id);

            if (organization == null)
            {
                return(BadRequest());
            }

            if (!_billingManager.CanAddUser(organization))
            {
                return(PlanLimitReached("Please upgrade your plan to add an additional user."));
            }

            var  currentUser = ExceptionlessUser;
            User user        = _userRepository.GetByEmailAddress(email);

            if (user != null)
            {
                if (!user.OrganizationIds.Contains(organization.Id))
                {
                    user.OrganizationIds.Add(organization.Id);
                    _userRepository.Save(user);
                }

                _mailer.SendAddedToOrganization(currentUser, organization, user);
            }
            else
            {
                Invite invite = organization.Invites.FirstOrDefault(i => String.Equals(i.EmailAddress, email, StringComparison.OrdinalIgnoreCase));
                if (invite == null)
                {
                    invite = new Invite {
                        Token        = Guid.NewGuid().ToString("N").ToLower(),
                        EmailAddress = email,
                        DateAdded    = DateTime.UtcNow
                    };
                    organization.Invites.Add(invite);
                    _repository.Save(organization);
                }

                _mailer.SendInvite(currentUser, organization, invite);
            }

            if (user != null)
            {
                return(Ok(new User {
                    EmailAddress = user.EmailAddress
                }));
            }

            return(Ok());
        }
示例#3
0
        public async Task <IHttpActionResult> AddUser(string id, string email)
        {
            if (String.IsNullOrEmpty(id) || !CanAccessOrganization(id) || String.IsNullOrEmpty(email))
            {
                return(NotFound());
            }

            Organization organization = _repository.GetById(id);

            if (organization == null)
            {
                return(NotFound());
            }

            if (!_billingManager.CanAddUser(organization))
            {
                return(PlanLimitReached("Please upgrade your plan to add an additional user."));
            }

            var  currentUser = ExceptionlessUser;
            User user        = _userRepository.GetByEmailAddress(email);

            if (user != null)
            {
                if (!user.OrganizationIds.Contains(organization.Id))
                {
                    user.OrganizationIds.Add(organization.Id);
                    _userRepository.Save(user);
                    _messagePublisher.Publish(new UserMembershipChanged {
                        ChangeType     = ChangeType.Added,
                        UserId         = user.Id,
                        OrganizationId = organization.Id
                    });
                }

                _mailer.SendAddedToOrganization(currentUser, organization, user);
            }
            else
            {
                Invite invite = organization.Invites.FirstOrDefault(i => String.Equals(i.EmailAddress, email, StringComparison.OrdinalIgnoreCase));
                if (invite == null)
                {
                    invite = new Invite {
                        Token        = StringExtensions.GetNewToken(),
                        EmailAddress = email.ToLowerInvariant(),
                        DateAdded    = DateTime.UtcNow
                    };
                    organization.Invites.Add(invite);
                    _repository.Save(organization);
                }

                _mailer.SendInvite(currentUser, organization, invite);
            }

            return(Ok(new User {
                EmailAddress = email
            }));
        }
示例#4
0
        public User Invite(string id, string emailAddress)
        {
            if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(emailAddress))
            {
                throw new HttpResponseException(BadRequestErrorResponseMessage());
            }

            Organization organization = GetEntity(id);

            if (organization == null)
            {
                throw new HttpResponseException(BadRequestErrorResponseMessage());
            }

            if (!_billingManager.CanAddUser(organization))
            {
                throw new HttpResponseException(PlanLimitReached("Please upgrade your plan to add an additional user."));
            }

            User user = _userRepository.GetByEmailAddress(emailAddress);

            if (user != null)
            {
                if (!user.OrganizationIds.Contains(organization.Id))
                {
                    user.OrganizationIds.Add(organization.Id);
                    _userRepository.Update(user);
                }

                _mailer.SendAddedToOrganizationAsync(User.UserEntity, organization, user);
            }
            else
            {
                Invite invite = organization.Invites.FirstOrDefault(i => String.Equals(i.EmailAddress, emailAddress, StringComparison.OrdinalIgnoreCase));
                if (invite == null)
                {
                    invite = new Invite {
                        Token        = Guid.NewGuid().ToString("N").ToLower(),
                        EmailAddress = emailAddress,
                        DateAdded    = DateTime.UtcNow
                    };
                    organization.Invites.Add(invite);
                    _repository.Update(organization);
                }

                _mailer.SendInviteAsync(User.UserEntity, organization, invite);
            }

            _notificationSender.OrganizationUpdated(organization.Id);
            return(user != null ? new User {
                EmailAddress = user.EmailAddress
            } : null);
        }