private void InitData() { HasPendingProfiles = CoreContext.UserManager.GetUsers().Any(u => u.ActivationStatus == EmployeeActivationStatus.Pending); EnableAddUsers = TenantStatisticsProvider.GetUsersCount() < TenantExtra.GetTenantQuota().ActiveUsers; CurrentUserFullAdmin = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsAdmin(); CurrentUserAdmin = CurrentUserFullAdmin || WebItemSecurity.IsProductAdministrator(WebItemManager.PeopleProductID, SecurityContext.CurrentAccount.ID); EnableAddVisitors = CoreContext.Configuration.Standalone || TenantStatisticsProvider.GetVisitorsCount() < TenantExtra.GetTenantQuota().ActiveUsers *Constants.CoefficientOfVisitors; }
protected Tuple <string, string, string> GetShoppingData(TenantQuota quota, string currency, int quantity) { var getLink = true; var buttonText = Resource.TariffButtonBuy; var infoText = string.Empty; var currentUsersCount = TenantStatisticsProvider.GetUsersCount(); var currentVisitorsCount = TenantStatisticsProvider.GetVisitorsCount(); var currentUsedSize = TenantStatisticsProvider.GetUsedSize(); var currentTariff = TenantExtra.GetCurrentTariff(); var currentQuota = TenantExtra.GetTenantQuota(); var language = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; var customerId = CoreContext.TenantManager.GetCurrentTenant().OwnerId.ToString(); var quotaActiveUsers = quota.ActiveUsers == -1 ? quantity : quota.ActiveUsers; var quotaMaxTotalSize = quota.ActiveUsers == -1 ? quota.MaxTotalSize * quantity : quota.MaxTotalSize; if (quotaActiveUsers < currentUsersCount || quotaMaxTotalSize < currentUsedSize || (!currentQuota.Free && (quotaActiveUsers * Constants.CoefficientOfVisitors) < currentVisitorsCount)) { getLink = false; } else if (Equals(quota.Id, currentQuota.Id) && quantity == currentTariff.Quantity) { buttonText = Resource.TariffButtonExtend; if (!currentTariff.Prolongable) { getLink = false; } else if (currentTariff.Autorenewal) { getLink = false; buttonText = Resource.TariffEnabledAutorenew; infoText = Resource.TariffRemarkProlongEnable; } } else if (currentTariff.Prolongable) { buttonText = Resource.TariffButtonBuy; infoText = Resource.TariffRemarkProlongDisable; } else if (currentTariff.State == TariffState.Paid && quotaActiveUsers < currentQuota.ActiveUsers) { getLink = false; buttonText = Resource.TariffButtonBuy; infoText = currentQuota.Year3 ? Resource.TariffRemarkDisabledYear : Resource.TariffRemarkDisabledMonth; } var link = getLink ? GetShoppingLink(quota, currency, language, customerId, quantity) : string.Empty; return(new Tuple <string, string, string>(buttonText, infoText, link)); }
protected void Page_Load(object sender, EventArgs e) { LinkText = CustomNamingPeople.Substitute <Resource>("InviteUsersToPortalLink").HtmlEncode(); if (CoreContext.Configuration.Personal) { EnableAddUsers = true; EnableAddVisitors = true; } else { EnableAddUsers = TenantStatisticsProvider.GetUsersCount() < TenantExtra.GetTenantQuota().ActiveUsers; EnableAddVisitors = CoreContext.Configuration.Standalone || TenantStatisticsProvider.GetVisitorsCount() < TenantExtra.GetTenantQuota().ActiveUsers *Constants.CoefficientOfVisitors; } }
public QuotaWrapper( Tenant tenant, CoreBaseSettings coreBaseSettings, CoreConfiguration configuration, TenantExtra tenantExtra, TenantStatisticsProvider tenantStatisticsProvider, AuthContext authContext, SettingsManager settingsManager, WebItemManager webItemManager, Constants constants) { TenantExtra = tenantExtra; TenantStatisticsProvider = tenantStatisticsProvider; WebItemManager = webItemManager; var quota = TenantExtra.GetTenantQuota(); var quotaRows = TenantStatisticsProvider.GetQuotaRows(tenant.TenantId).ToList(); StorageSize = (ulong)Math.Max(0, quota.MaxTotalSize); UsedSize = (ulong)Math.Max(0, quotaRows.Sum(r => r.Counter)); MaxUsersCount = quota.ActiveUsers; UsersCount = coreBaseSettings.Personal ? 1 : TenantStatisticsProvider.GetUsersCount(); MaxVisitors = coreBaseSettings.Standalone ? -1 : constants.CoefficientOfVisitors * quota.ActiveUsers; VisitorsCount = coreBaseSettings.Personal ? 0 : TenantStatisticsProvider.GetVisitorsCount(); StorageUsage = quotaRows .Select(x => new QuotaUsage { Path = x.Path.TrimStart('/').TrimEnd('/'), Size = x.Counter, }) .ToList(); if (coreBaseSettings.Personal && SetupInfo.IsVisibleSettings("PersonalMaxSpace")) { UserStorageSize = configuration.PersonalMaxSpace(settingsManager); var webItem = WebItemManager[WebItemManager.DocumentsProductID]; if (webItem.Context.SpaceUsageStatManager is IUserSpaceUsage spaceUsageManager) { UserUsedSize = spaceUsageManager.GetUserSpaceUsage(authContext.CurrentAccount.ID); } } MaxFileSize = Math.Min(AvailableSize, (ulong)quota.MaxFileSize); }
public static QuotaWrapper GetCurrent() { var quota = TenantExtra.GetTenantQuota(); var quotaRows = TenantStatisticsProvider.GetQuotaRows(TenantProvider.CurrentTenantID).ToList(); var result = new QuotaWrapper { StorageSize = (ulong)Math.Max(0, quota.MaxTotalSize), UsedSize = (ulong)Math.Max(0, quotaRows.Sum(r => r.Counter)), MaxUsersCount = TenantExtra.GetTenantQuota().ActiveUsers, UsersCount = CoreContext.Configuration.Personal ? 1 : TenantStatisticsProvider.GetUsersCount(), MaxVisitors = CoreContext.Configuration.Standalone ? -1 : Constants.CoefficientOfVisitors * TenantExtra.GetTenantQuota().ActiveUsers, VisitorsCount = TenantStatisticsProvider.GetVisitorsCount(), StorageUsage = quotaRows .Select(x => new QuotaUsage { Path = x.Path.TrimStart('/').TrimEnd('/'), Size = x.Counter, }) .ToList() }; if (CoreContext.Configuration.Personal && SetupInfo.IsVisibleSettings("PersonalMaxSpace")) { result.UserStorageSize = CoreContext.Configuration.PersonalMaxSpace; var webItem = WebItemManager.Instance[WebItemManager.DocumentsProductID]; var spaceUsageManager = webItem.Context.SpaceUsageStatManager as IUserSpaceUsage; if (spaceUsageManager != null) { result.UserUsedSize = spaceUsageManager.GetUserSpaceUsage(SecurityContext.CurrentAccount.ID); } } result.MaxFileSize = Math.Min(result.AvailableSize, (ulong)quota.MaxFileSize); return(result); }
public bool CanAddVisitor() { return(CoreContext.Configuration.Standalone || TenantStatisticsProvider.GetVisitorsCount() < TenantExtra.GetTenantQuota().ActiveUsers *Constants.CoefficientOfVisitors); }
protected void Page_Load(object sender, EventArgs e) { Page.RegisterBodyScripts("~/js/third-party/xregexp.js", "~/UserControls/Management/ConfirmInviteActivation/js/confirm_invite_activation.js") .RegisterStyle("~/UserControls/Management/ConfirmInviteActivation/css/confirm_invite_activation.less"); var uid = Guid.Empty; try { uid = new Guid(Request["uid"]); } catch { } var email = GetEmailAddress(); if (_type != ConfirmType.Activation && AccountLinkControl.IsNotEmpty && !CoreContext.Configuration.Personal) { var thrd = (AccountLinkControl)LoadControl(AccountLinkControl.Location); thrd.InviteView = true; thrd.ClientCallback = "loginJoinCallback"; thrdParty.Visible = true; thrdParty.Controls.Add(thrd); } Page.Title = HeaderStringHelper.GetPageTitle(Resource.Authorization); UserInfo user; try { SecurityContext.CurrentAccount = ASC.Core.Configuration.Constants.CoreSystem; user = CoreContext.UserManager.GetUserByEmail(email); var usr = CoreContext.UserManager.GetUsers(uid); if (usr.ID.Equals(Constants.LostUser.ID) || usr.ID.Equals(ASC.Core.Configuration.Constants.Guest.ID)) { usr = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId); } var photoData = UserPhotoManager.GetUserPhotoData(usr.ID, UserPhotoManager.MediumFotoSize); _userAvatar = photoData == null?usr.GetMediumPhotoURL() : "data:image/png;base64," + Convert.ToBase64String(photoData); _userName = usr.DisplayUserName(true); _userPost = (usr.Title ?? "").HtmlEncode(); } finally { SecurityContext.Logout(); } if (_type == ConfirmType.LinkInvite || _type == ConfirmType.EmpInvite) { if (!CoreContext.Configuration.Personal) { if (_employeeType == EmployeeType.User && TenantStatisticsProvider.GetUsersCount() >= TenantExtra.GetTenantQuota().ActiveUsers) { ShowError(UserControlsCommonResource.TariffUserLimitReason); return; } if (_employeeType == EmployeeType.Visitor && !(CoreContext.Configuration.Standalone || TenantStatisticsProvider.GetVisitorsCount() < TenantExtra.GetTenantQuota().ActiveUsers *Constants.CoefficientOfVisitors)) { ShowError(UserControlsCommonResource.TariffVisitorLimitReason); return; } } if (!user.ID.Equals(Constants.LostUser.ID)) { ShowError(CustomNamingPeople.Substitute <Resource>("ErrorEmailAlreadyExists")); return; } } else if (_type == ConfirmType.Activation) { if (user.IsActive) { Response.Redirect(CommonLinkUtility.GetDefault()); return; } if (user.ID.Equals(Constants.LostUser.ID) || user.Status == EmployeeStatus.Terminated) { ShowError(string.Format(Resource.ErrorUserNotFoundByEmail, email)); return; } } var tenant = CoreContext.TenantManager.GetCurrentTenant(); if (tenant != null) { var settings = IPRestrictionsSettings.Load(); if (settings.Enable && !IPSecurity.IPSecurity.Verify(tenant)) { ShowError(Resource.ErrorAccessRestricted); return; } } if (!IsPostBack) { return; } var firstName = GetFirstName(); var lastName = GetLastName(); var passwordHash = (Request["passwordHash"] ?? "").Trim(); var mustChangePassword = false; LoginProfile thirdPartyProfile; //thirdPartyLogin confirmInvite if (Request["__EVENTTARGET"] == "thirdPartyLogin") { var valueRequest = Request["__EVENTARGUMENT"]; thirdPartyProfile = new LoginProfile(valueRequest); if (!string.IsNullOrEmpty(thirdPartyProfile.AuthorizationError)) { // ignore cancellation if (thirdPartyProfile.AuthorizationError != "Canceled at provider") { ShowError(HttpUtility.HtmlEncode(thirdPartyProfile.AuthorizationError)); } return; } if (string.IsNullOrEmpty(thirdPartyProfile.EMail)) { ShowError(HttpUtility.HtmlEncode(Resource.ErrorNotCorrectEmail)); return; } } if (Request["__EVENTTARGET"] == "confirmInvite") { if (String.IsNullOrEmpty(email)) { _errorMessage = Resource.ErrorEmptyUserEmail; return; } if (!email.TestEmailRegex()) { _errorMessage = Resource.ErrorNotCorrectEmail; return; } if (String.IsNullOrEmpty(firstName)) { _errorMessage = Resource.ErrorEmptyUserFirstName; return; } if (String.IsNullOrEmpty(lastName)) { _errorMessage = Resource.ErrorEmptyUserLastName; return; } if (String.IsNullOrEmpty(passwordHash)) { _errorMessage = Resource.ErrorPasswordEmpty; return; } } var userID = Guid.Empty; try { SecurityContext.CurrentAccount = ASC.Core.Configuration.Constants.CoreSystem; if (_type == ConfirmType.EmpInvite || _type == ConfirmType.LinkInvite) { if (!CoreContext.Configuration.Personal && TenantStatisticsProvider.GetUsersCount() >= TenantExtra.GetTenantQuota().ActiveUsers&& _employeeType == EmployeeType.User) { ShowError(UserControlsCommonResource.TariffUserLimitReason); return; } UserInfo newUser; if (Request["__EVENTTARGET"] == "confirmInvite") { var fromInviteLink = _type == ConfirmType.LinkInvite; newUser = CreateNewUser(firstName, lastName, email, passwordHash, _employeeType, fromInviteLink); var messageAction = _employeeType == EmployeeType.User ? MessageAction.UserCreatedViaInvite : MessageAction.GuestCreatedViaInvite; MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, messageAction, MessageTarget.Create(newUser.ID), newUser.DisplayUserName(false)); userID = newUser.ID; } if (Request["__EVENTTARGET"] == "thirdPartyLogin") { if (String.IsNullOrEmpty(passwordHash)) { passwordHash = UserManagerWrapper.GeneratePassword(); mustChangePassword = true; } var valueRequest = Request["__EVENTARGUMENT"]; thirdPartyProfile = new LoginProfile(valueRequest); newUser = CreateNewUser(GetFirstName(thirdPartyProfile), GetLastName(thirdPartyProfile), GetEmailAddress(thirdPartyProfile), passwordHash, _employeeType, false); var messageAction = _employeeType == EmployeeType.User ? MessageAction.UserCreatedViaInvite : MessageAction.GuestCreatedViaInvite; MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, messageAction, MessageTarget.Create(newUser.ID), newUser.DisplayUserName(false)); userID = newUser.ID; if (!String.IsNullOrEmpty(thirdPartyProfile.Avatar)) { SaveContactImage(userID, thirdPartyProfile.Avatar); } var linker = new AccountLinker("webstudio"); linker.AddLink(userID.ToString(), thirdPartyProfile); } } else if (_type == ConfirmType.Activation) { if (!UserFormatter.IsValidUserName(firstName, lastName)) { throw new Exception(Resource.ErrorIncorrectUserName); } SecurityContext.SetUserPasswordHash(user.ID, passwordHash); user.ActivationStatus = EmployeeActivationStatus.Activated; user.FirstName = firstName; user.LastName = lastName; CoreContext.UserManager.SaveUserInfo(user); userID = user.ID; //notify if (user.IsVisitor()) { StudioNotifyService.Instance.GuestInfoAddedAfterInvite(user); MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, MessageAction.GuestActivated, MessageTarget.Create(user.ID), user.DisplayUserName(false)); } else { StudioNotifyService.Instance.UserInfoAddedAfterInvite(user); MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, MessageAction.UserActivated, MessageTarget.Create(user.ID), user.DisplayUserName(false)); } } } catch (SecurityContext.PasswordException) { _errorMessage = HttpUtility.HtmlEncode(Resource.ErrorPasswordRechange); return; } catch (Exception exception) { _errorMessage = HttpUtility.HtmlEncode(exception.Message); return; } finally { SecurityContext.Logout(); } user = CoreContext.UserManager.GetUsers(userID); try { CookiesManager.AuthenticateMeAndSetCookies(user.Email, passwordHash, MessageAction.LoginSuccess); StudioNotifyService.Instance.UserHasJoin(); if (mustChangePassword) { StudioNotifyService.Instance.UserPasswordChange(user); } } catch (Exception exception) { (Page as Confirm).ErrorMessage = HttpUtility.HtmlEncode(exception.Message); return; } UserHelpTourHelper.IsNewUser = true; if (CoreContext.Configuration.Personal) { PersonalSettings.IsNewUser = true; } Response.Redirect(CommonLinkUtility.GetDefault()); }
private bool CheckStartupEnabled(TenantQuota currentQuota, TenantQuota startupQuota, out string errorMessage) { errorMessage = string.Empty; if (!currentQuota.Trial) { errorMessage = UserControlsCommonResource.SaasTariffErrorTrial; return(false); } if (TenantStatisticsProvider.GetUsersCount() > startupQuota.ActiveUsers) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorUsers, startupQuota.ActiveUsers); return(false); } if (TenantStatisticsProvider.GetVisitorsCount() > 0) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorGuests, 0); return(false); } var currentTenant = CoreContext.TenantManager.GetCurrentTenant(); var admins = WebItemSecurity.GetProductAdministrators(Guid.Empty); if (admins.Any(admin => admin.ID != currentTenant.OwnerId)) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorAdmins, 1); return(false); } if (TenantStatisticsProvider.GetUsedSize() > startupQuota.MaxTotalSize) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorStorage, FileSizeComment.FilesSizeToString(startupQuota.MaxTotalSize)); return(false); } var authServiceList = new AuthorizationKeys().AuthServiceList.Where(x => x.CanSet); foreach (var service in authServiceList) { if (service.Props.Any(r => !string.IsNullOrEmpty(r.Value))) { errorMessage = UserControlsCommonResource.SaasTariffErrorThirparty; return(false); } } if (!TenantWhiteLabelSettings.Load().IsDefault) { errorMessage = UserControlsCommonResource.SaasTariffErrorWhiteLabel; return(false); } if (!string.IsNullOrEmpty(currentTenant.MappedDomain)) { errorMessage = UserControlsCommonResource.SaasTariffErrorDomain; return(false); } var accountLinker = new AccountLinker("webstudio"); foreach (var user in CoreContext.UserManager.GetUsers(EmployeeStatus.All)) { var linkedAccounts = accountLinker.GetLinkedProfiles(user.ID.ToString()); if (linkedAccounts.Any()) { errorMessage = UserControlsCommonResource.SaasTariffErrorOauth; return(false); } } if (SsoSettingsV2.Load().EnableSso) { errorMessage = UserControlsCommonResource.SaasTariffErrorSso; return(false); } if (ActiveDirectory.Base.Settings.LdapSettings.Load().EnableLdapAuthentication) { errorMessage = UserControlsCommonResource.SaasTariffErrorLdap; return(false); } using (var service = new BackupServiceClient()) { var scheduleResponse = service.GetSchedule(currentTenant.TenantId); if (scheduleResponse != null) { errorMessage = UserControlsCommonResource.SaasTariffErrorAutoBackup; return(false); } } return(true); }
protected void Page_Load(object sender, EventArgs e) { var userInfo = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); IsAdmin = userInfo.IsAdmin() || WebItemSecurity.IsProductAdministrator(WebItemManager.PeopleProductID, userInfo.ID); Actions = new AllowedActions(userInfo); var quota = TenantExtra.GetTenantQuota(); IsFreeTariff = quota.Free && !quota.Open; IsStandalone = CoreContext.Configuration.Standalone; DisplayPayments = TenantExtra.EnableTariffSettings && (!CoreContext.Configuration.Standalone || quota.ActiveUsers != LicenseReader.MaxUserCount); if (DisplayPayments) { int notifyCount; int.TryParse(ConfigurationManagerExtension.AppSettings["web.tariff-notify.user"] ?? "5", out notifyCount); DisplayPaymentsFirstUser = notifyCount > 0 && quota.ActiveUsers - TenantStatisticsProvider.GetUsersCount() < notifyCount; DisplayPaymentsFirstGuest = !IsStandalone && notifyCount > 0 && quota.ActiveUsers * Constants.CoefficientOfVisitors - TenantStatisticsProvider.GetVisitorsCount() < notifyCount; } var controlEmailChange = (UserEmailChange)LoadControl(UserEmailChange.Location); controlEmailChange.UserInfo = userInfo; controlEmailChange.RegisterStylesAndScripts = true; userEmailChange.Controls.Add(controlEmailChange); loaderHolder.Controls.Add(LoadControl(LoaderPage.Location)); userConfirmationDelete.Controls.Add(LoadControl(ConfirmationDeleteUser.Location)); if (Actions.AllowEdit) { userPwdChange.Controls.Add(LoadControl(PwdTool.Location)); } Title = HeaderStringHelper.GetPageTitle(PeopleResource.ProductName); HelpLink = CommonLinkUtility.GetHelpLink(); }
protected void Page_Load(object sender, EventArgs e) { if (!SecurityContext.CheckPermissions(Constants.Action_AddRemoveUser)) { Response.Redirect(CommonLinkUtility.GetDefault()); } EnableUsers = TenantExtra.GetTenantQuota().ActiveUsers - TenantStatisticsProvider.GetUsersCount(); EnableGuests = Constants.CoefficientOfVisitors * TenantExtra.GetTenantQuota().ActiveUsers - TenantStatisticsProvider.GetVisitorsCount(); EnableGuests = EnableGuests >= 0 ? EnableGuests : 0; IsStandalone = CoreContext.Configuration.Standalone; var tariff = (Studio.UserControls.Management.TariffLimitExceed)LoadControl(Studio.UserControls.Management.TariffLimitExceed.Location); Tariff.Controls.Add(tariff); var quota = TenantExtra.GetTenantQuota(); PeopleLimit = Math.Min(quota.ActiveUsers - TenantStatisticsProvider.GetUsersCount(), 0); FreeTariff = (quota.Free || quota.NonProfit || quota.Trial) && !quota.Open; HelpLink = CommonLinkUtility.GetHelpLink(); icon.Options.IsPopup = true; icon.Options.PopupContainerCssClass = "okcss popupContainerClass"; icon.Options.OnCancelButtonClick = "ASC.People.Import.hideInfoWindow('okcss');"; limitPanel.Options.IsPopup = true; limitPanel.Options.OnCancelButtonClick = "ASC.People.Import.hideImportUserLimitPanel();"; Utility.RegisterTypeForAjax(GetType()); RegisterScript(); }