public bool CanAddOrganization(User user) { if (user == null) return false; var organizations = _organizationRepository.GetByIds(user.OrganizationIds).Where(o => o.PlanId == FreePlan.Id); return !organizations.Any(); }
public bool CanDownGrade(Organization organization, BillingPlan plan, User user, out string message) { if (organization == null || String.IsNullOrWhiteSpace(organization.Id)) { message = "Invalid Organization"; return false; } int currentNumberOfUsers = _userRepository.GetByOrganizationId(organization.Id).Count() + organization.Invites.Count; int maxUsers = plan.MaxUsers != -1 ? plan.MaxUsers : int.MaxValue; if (currentNumberOfUsers > maxUsers) { message = String.Format("Please remove {0} user{1} and try again.", currentNumberOfUsers - maxUsers, (currentNumberOfUsers - maxUsers) > 0 ? "s" : String.Empty); return false; } int maxProjects = plan.MaxProjects != -1 ? plan.MaxProjects : int.MaxValue; if (organization.ProjectCount > maxProjects) { message = String.Format("Please remove {0} project{1} and try again.", organization.ProjectCount - maxProjects, (organization.ProjectCount - maxProjects) > 0 ? "s" : String.Empty); return false; } // TODO: We need to make this smarter. if (organization.OverageDays != null && organization.OverageDays.Count(d => d.Day > DateTime.Now.AddDays(-30)) > 0 && plan.MaxErrorsPerDay < GetBillingPlan(organization.PlanId).MaxErrorsPerDay) { message = "You would exceed the maximum errors per day plan limit."; return false; } // Ensure the user can't be apart of more than one free plan. if (String.Equals(plan.Id, FreePlan.Id) && user != null && _organizationRepository.GetByIds(user.OrganizationIds).Any(o => String.Equals(o.PlanId, FreePlan.Id))) { message = "You already have one free account. You are not allowed to create more than one free account."; return false; } message = String.Empty; return true; }
public bool CanDownGrade(Organization organization, BillingPlan plan, User user, out string message) { if (organization == null || String.IsNullOrWhiteSpace(organization.Id)) { message = "Invalid Organization"; return false; } int currentNumberOfUsers = _userRepository.GetByOrganizationId(organization.Id).Count() + organization.Invites.Count; int maxUsers = plan.MaxUsers != -1 ? plan.MaxUsers : int.MaxValue; if (currentNumberOfUsers > maxUsers) { message = String.Format("Please remove {0} user{1} and try again.", currentNumberOfUsers - maxUsers, (currentNumberOfUsers - maxUsers) > 0 ? "s" : String.Empty); return false; } int maxProjects = plan.MaxProjects != -1 ? plan.MaxProjects : int.MaxValue; long projectCount = _projectRepository.GetCountByOrganizationId(organization.Id); if (projectCount > maxProjects) { message = String.Format("Please remove {0} project{1} and try again.", projectCount - maxProjects, (projectCount - maxProjects) > 0 ? "s" : String.Empty); return false; } // Ensure the user can't be apart of more than one free plan. if (String.Equals(plan.Id, FreePlan.Id) && user != null && _organizationRepository.GetByIds(user.OrganizationIds).Any(o => String.Equals(o.PlanId, FreePlan.Id))) { message = "You already have one free account. You are not allowed to create more than one free account."; return false; } message = String.Empty; return true; }
public ExceptionlessPrincipal(User user) { UserEntity = user; Identity = new GenericIdentity(user.EmailAddress, "User"); _roles.Add(AuthorizationRoles.User); if (user.Roles != null) _roles.AddRange(user.Roles); }
public async Task SendVerifyEmailAsync(User user) { MailMessage msg = _emailGenerator.GenerateMessage(new UserModel { User = user, BaseUrl = Settings.Current.BaseURL }, "VerifyEmail"); msg.To.Add(user.EmailAddress); await QueueMessage(msg); }
public void SendVerifyEmail(User user) { MailMessage msg = _emailGenerator.GenerateMessage(new UserModel { User = user, BaseUrl = Settings.Current.BaseURL }, "VerifyEmail"); msg.To.Add(user.EmailAddress); SendMessage(msg); }
public async Task SendPaymentFailedAsync(User owner, Organization organization) { MailMessage msg = _emailGenerator.GenerateMessage(new PaymentModel { Owner = owner, Organization = organization, BaseUrl = Settings.Current.BaseURL }, "PaymentFailed"); msg.To.Add(owner.EmailAddress); await QueueMessage(msg); }
public async Task SendInviteAsync(User sender, Organization organization, Invite invite) { MailMessage msg = _emailGenerator.GenerateMessage(new InviteModel { Sender = sender, Organization = organization, Invite = invite, BaseUrl = Settings.Current.BaseURL }, "Invite"); msg.To.Add(invite.EmailAddress); await QueueMessage(msg); }
public async Task SendPasswordResetAsync(User user) { if (user == null || String.IsNullOrEmpty(user.PasswordResetToken)) return; MailMessage msg = _emailGenerator.GenerateMessage(new UserModel { User = user, BaseUrl = Settings.Current.BaseURL }, "PasswordReset"); msg.To.Add(user.EmailAddress); await QueueMessage(msg); }
public async Task SendAddedToOrganizationAsync(User sender, Organization organization, User user) { MailMessage msg = _emailGenerator.GenerateMessage(new AddedToOrganizationModel { Sender = sender, Organization = organization, User = user, BaseUrl = Settings.Current.BaseURL }, "AddedToOrganization"); msg.To.Add(user.EmailAddress); await QueueMessage(msg); }
public static User GenerateUser(bool generateId = false, string id = null, string organizationId = null, string emailAddress = null, IEnumerable<string> roles = null) { var user = new User { Id = id.IsNullOrEmpty() ? generateId ? ObjectId.GenerateNewId().ToString() : TestConstants.UserId : id, EmailAddress = emailAddress.IsNullOrEmpty() ? String.Concat(RandomHelper.GetPronouncableString(6), "@", RandomHelper.GetPronouncableString(6), ".com") : emailAddress, Password = TestConstants.UserPassword, FullName = "Eric Smith", PasswordResetToken = Guid.NewGuid().ToString() }; user.OrganizationIds.Add(organizationId.IsNullOrEmpty() ? TestConstants.OrganizationId : organizationId); if (roles != null) user.Roles.AddRange(roles); return user; }
public void SendPaymentFailed(User owner, Organization organization) {}
public void SendAddedToOrganization(User sender, Organization organization, User user) {}
public void SendVerifyEmail(User user) {}
public void SendInvite(User sender, Organization organization, Invite invite) {}
public Task SendPaymentFailedAsync(User owner, Organization organization) { return Task.FromResult(0); }
public void SendPasswordReset(User user) {}
public Task SendPaymentFailedAsync(User owner, Organization organization) { return Task.Delay(0); }
public Task SendAddedToOrganizationAsync(User sender, Organization organization, User user) { return Task.Run(() => SendAddedToOrganization(sender, organization, user)); }
public Task SendAddedToOrganizationAsync(User sender, Organization organization, User user) { return Task.FromResult(0); }
public Task SendAddedToOrganizationAsync(User sender, Organization organization, User user) { return Task.Delay(0); }
public Task SendInviteAsync(User sender, Organization organization, Invite invite) { return Task.FromResult(0); }
public ActionResult Signup(RegisterModel model, string returnUrl, string token) { if (ModelState.IsValid) { // Attempt to register the user try { User eu = _membershipProvider.GetUserByEmailAddress(model.EmailAddress); if (eu != null) { ModelState.AddModelError("EmailAddress", "A user already exists with this email address."); return View(model); } var user = new User { EmailAddress = model.EmailAddress, Password = model.Password, FullName = model.FullName }; user.Roles.Add(AuthorizationRoles.User); // Add the GlobalAdmin role to the first user of the system. if (!_isFirstUserChecked) { _isFirstUserChecked = true; if (_userRepository.All().FirstOrDefault() == null) user.Roles.Add(AuthorizationRoles.GlobalAdmin); } _membershipProvider.CreateAccount(user); if (!String.IsNullOrEmpty(token)) { AddInvitedUserToOrganization(token, user); } else { // TODO: We should verify that the passed in token was valid. If it wasn't, we should resend the verify email token. user.VerifyEmailAddressToken = _membershipProvider.GenerateVerifyEmailToken(user.EmailAddress); _mailer.SendVerifyEmailAsync(user); } if (Settings.Current.WebsiteMode == WebsiteMode.Dev && user.Roles.Contains(AuthorizationRoles.GlobalAdmin)) { _dataHelper.CreateSampleOrganizationAndProject(user.Id); return String.IsNullOrEmpty(returnUrl) ? RedirectToAction("Index", "Project") : RedirectToLocal(returnUrl); } return String.IsNullOrEmpty(returnUrl) ? RedirectToAction("Add", "Project") : RedirectToLocal(returnUrl); } catch (MembershipException e) { _isFirstUserChecked = false; ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public Task SendVerifyEmailAsync(User user) { return Task.FromResult(0); }
public void ApplyBillingPlan(Organization organization, BillingPlan plan, User user, bool updateBillingPrice = true) { organization.PlanId = plan.Id; organization.BillingChangeDate = DateTime.Now; if (updateBillingPrice) organization.BillingPrice = plan.Price; organization.BillingChangedByUserId = user.Id; organization.MaxUsers = plan.MaxUsers; organization.MaxProjects = plan.MaxProjects; organization.RetentionDays = plan.RetentionDays; organization.MaxEventsPerMonth = plan.MaxEventsPerMonth; organization.HasPremiumFeatures = plan.HasPremiumFeatures; }
public Task SendInviteAsync(User sender, Organization organization, Invite invite) { return Task.Delay(0); }
public Task SendPasswordResetAsync(User user) { return Task.Delay(0); }
public Task SendVerifyEmailAsync(User user) { return Task.Delay(0); }
private void AddInvitedUserToOrganization(string token, User user) { Invite invite; Organization organization = _organizationRepository.GetByInviteToken(token, out invite); if (organization != null) { if (!user.IsEmailAddressVerified && String.Equals(user.EmailAddress, invite.EmailAddress, StringComparison.OrdinalIgnoreCase)) { user.IsEmailAddressVerified = true; _userRepository.Update(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.Update(user); organization.Invites.Remove(invite); _organizationRepository.Update(organization); _notificationSender.OrganizationUpdated(organization.Id); } }
public Task SendPasswordResetAsync(User sender) { return Task.FromResult(0); }