// Copyright (c) 2014, Outercurve Foundation. // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // - Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // - Neither the name of the Outercurve Foundation nor the names of its // contributors may be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; using WebsitePanel.EnterpriseServer; using WebsitePanel.EnterpriseServer.Base.HostedSolution; using WebsitePanel.Providers.HostedSolution; using WebsitePanel.Providers.ResultObjects; namespace WebsitePanel.Portal.HostedSolution { public partial class UserGeneralSettings : WebsitePanelModuleBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindServiceLevels(); BindSettings(); MailboxTabsId.Visible = (PanelRequest.Context == "Mailbox"); UserTabsId.Visible = (PanelRequest.Context == "User"); } } private void BindSettings() { try { password.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.EXCHANGE_POLICY, "MailboxPasswordPolicy"); PasswordPolicyResult passwordPolicy = ES.Services.Organizations.GetPasswordPolicy(PanelRequest.ItemID); if (passwordPolicy.IsSuccess) { password.MinimumLength = passwordPolicy.Value.MinLength; if (passwordPolicy.Value.IsComplexityEnable) { password.MinimumNumbers = 1; password.MinimumSymbols = 1; password.MinimumUppercase = 1; } } // get settings OrganizationUser user = ES.Services.Organizations.GetUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID); litDisplayName.Text = PortalAntiXSS.Encode(user.DisplayName); lblUserDomainName.Text = user.DomainUserName; // bind form txtDisplayName.Text = user.DisplayName; chkDisable.Checked = user.Disabled; txtFirstName.Text = user.FirstName; txtInitials.Text = user.Initials; txtLastName.Text = user.LastName; txtJobTitle.Text = user.JobTitle; txtCompany.Text = user.Company; txtDepartment.Text = user.Department; txtOffice.Text = user.Office; manager.SetAccount(user.Manager); txtBusinessPhone.Text = user.BusinessPhone; txtFax.Text = user.Fax; txtHomePhone.Text = user.HomePhone; txtMobilePhone.Text = user.MobilePhone; txtPager.Text = user.Pager; txtWebPage.Text = user.WebPage; txtAddress.Text = user.Address; txtCity.Text = user.City; txtState.Text = user.State; txtZip.Text = user.Zip; country.Country = user.Country; txtNotes.Text = user.Notes; txtExternalEmailAddress.Text = user.ExternalEmail; txtExternalEmailAddress.Enabled = user.AccountType == ExchangeAccountType.User; lblUserDomainName.Text = user.DomainUserName; txtSubscriberNumber.Text = user.SubscriberNumber; lblUserPrincipalName.Text = user.UserPrincipalName; PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_ISCONSUMER)) { if (cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue != 1) { locSubscriberNumber.Visible = false; txtSubscriberNumber.Visible = false; } } if (user.LevelId > 0 && secServiceLevels.Visible) { secServiceLevels.IsCollapsed = false; ServiceLevel serviceLevel = ES.Services.Organizations.GetSupportServiceLevel(user.LevelId); litServiceLevel.Visible = true; litServiceLevel.Text = serviceLevel.LevelName; litServiceLevel.ToolTip = serviceLevel.LevelDescription; bool addLevel = ddlServiceLevels.Items.FindByValue(serviceLevel.LevelId.ToString()) == null; addLevel = addLevel && cntx.Quotas.ContainsKey(Quotas.SERVICE_LEVELS + serviceLevel.LevelName); addLevel = addLevel ? cntx.Quotas[Quotas.SERVICE_LEVELS + serviceLevel.LevelName].QuotaAllocatedValue != 0 : addLevel; if (addLevel) { ddlServiceLevels.Items.Add(new ListItem(serviceLevel.LevelName, serviceLevel.LevelId.ToString())); } bool levelInDDL = ddlServiceLevels.Items.FindByValue(serviceLevel.LevelId.ToString()) != null; if (levelInDDL) { ddlServiceLevels.Items.FindByValue(string.Empty).Selected = false; ddlServiceLevels.Items.FindByValue(serviceLevel.LevelId.ToString()).Selected = true; } } chkVIP.Checked = user.IsVIP && secServiceLevels.Visible; imgVipUser.Visible = user.IsVIP && secServiceLevels.Visible; if (cntx.Quotas.ContainsKey(Quotas.ORGANIZATION_ALLOWCHANGEUPN)) { if (cntx.Quotas[Quotas.ORGANIZATION_ALLOWCHANGEUPN].QuotaAllocatedValue != 1) { lblUserPrincipalName.Visible = true; upn.Visible = false; ddlEmailAddresses.Visible = false; btnSetUserPrincipalName.Visible = false; chkInherit.Visible = false; } else { lblUserPrincipalName.Visible = false; upn.Visible = false; ddlEmailAddresses.Visible = false; btnSetUserPrincipalName.Visible = true; chkInherit.Visible = true; if (user.AccountType == ExchangeAccountType.Mailbox) { ddlEmailAddresses.Visible = true; WebsitePanel.EnterpriseServer.ExchangeEmailAddress[] emails = ES.Services.ExchangeServer.GetMailboxEmailAddresses(PanelRequest.ItemID, PanelRequest.AccountID); foreach (WebsitePanel.EnterpriseServer.ExchangeEmailAddress mail in emails) { ListItem li = new ListItem(); li.Text = mail.EmailAddress; li.Value = mail.EmailAddress; li.Selected = mail.IsPrimary; ddlEmailAddresses.Items.Add(li); } foreach (ListItem li in ddlEmailAddresses.Items) { if (li.Value == user.UserPrincipalName) { ddlEmailAddresses.ClearSelection(); li.Selected = true; break; } } } else { upn.Visible = true; if (!string.IsNullOrEmpty(user.UserPrincipalName)) { string[] Tmp = user.UserPrincipalName.Split('@'); upn.AccountName = Tmp[0]; if (Tmp.Length > 1) { upn.DomainName = Tmp[1]; } } } } } if (user.Locked) chkLocked.Enabled = true; else chkLocked.Enabled = false; chkLocked.Checked = user.Locked; password.ValidationEnabled = true; password.Password = string.Empty; } catch (Exception ex) { messageBox.ShowErrorMessage("ORGANIZATION_GET_USER_SETTINGS", ex); } } private void BindServiceLevels() { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels)) { List enabledServiceLevels = new List(); foreach (var quota in cntx.Quotas.Where(x => x.Key.Contains(Quotas.SERVICE_LEVELS))) { foreach (var serviceLevel in ES.Services.Organizations.GetSupportServiceLevels()) { if (quota.Key.Replace(Quotas.SERVICE_LEVELS, "") == serviceLevel.LevelName && CheckServiceLevelQuota(quota.Value)) { enabledServiceLevels.Add(serviceLevel); } } } ddlServiceLevels.DataSource = enabledServiceLevels; ddlServiceLevels.DataTextField = "LevelName"; ddlServiceLevels.DataValueField = "LevelId"; ddlServiceLevels.DataBind(); ddlServiceLevels.Items.Insert(0, new ListItem("