private bool UpdateUser() { try { if (!currentUserCanModifyUser && !currentUserCanModifySelfUser) throw new Exception(GetMessageRaw("ExceptionText.YouDontHaveRightsToModifyUser")); if (!this.ExistUserEmail(tbEmail.Text)) throw new Exception(GetMessageRaw("Message.DuplicateEmail")); user.Email = tbEmail.Text; user.Comment = tbComment.Text; user.IsApproved = cbIsApproved.Checked; user.DisplayName = tbDisplayName.Text; user.FirstName = tbFirstName.Text; user.SecondName = tbSecondName.Text; user.LastName = tbLastName.Text; user.SiteId = ddlSite.SelectedValue; DateTime birthdayDate; DateTime.TryParse(tbBirthdayDate.Text, out birthdayDate); user.BirthdayDate = birthdayDate; user.Gender = Enum.IsDefined(typeof(BXUserGender), ddlGender.SelectedValue) ? (BXUserGender)Enum.Parse(typeof(BXUserGender), ddlGender.SelectedValue) : BXUserGender.Unknown; user.CustomValues.Override(CustomFieldList1.Save()); if (aifImage.DeleteFile) user.ImageId = 0; BXFile f = SaveFile(); if (f != null) user.ImageId = f.Id; try { user.Update(); } catch { if (f != null) f.Delete(); throw; } if (!String.IsNullOrEmpty(tbNewPassword.Text)) { try { if (BXUserManager.Provider.MinRequiredPasswordLength > 0 && tbNewPassword.Text.Length < BXUserManager.Provider.MinRequiredPasswordLength) throw new PublicException(string.Format(GetMessageRaw("ExceptionText.PasswordLength"), BXUserManager.Provider.MinRequiredPasswordLength.ToString())); if (BXUserManager.Provider.MinRequiredNonAlphanumericCharacters > 0 && !CheckAlphanumerics(tbNewPassword.Text, BXUserManager.Provider.MinRequiredNonAlphanumericCharacters)) throw new PublicException(string.Format(GetMessageRaw("ExceptionText.NonAlphanumerics"), BXUserManager.Provider.MinRequiredNonAlphanumericCharacters)); if (!(user.IsBuiltInProvider ? BXUserManager.Provider.ChangePassword(user.UserName, tbNewPassword.Text) : user.ChangePassword(tbPassword.Text, tbNewPassword.Text))) throw new PublicException(GetMessageRaw("ExceptionText.ChangeOfPasswordFailed")); } catch (PublicException) { throw; } catch (Exception ex) { throw new ArgumentException(GetMessageRaw("ExceptionText.ChangeOfPasswordFailed"), ex); } } MembershipProvider provider = BXUserManager.GetProvider(user.ProviderName); if (provider != null && provider.RequiresQuestionAndAnswer && !String.IsNullOrEmpty(tbAnswer.Text)) { bool res = user.ChangePasswordQuestionAndAnswer( (!String.IsNullOrEmpty(tbNewPassword.Text) ? tbNewPassword.Text : tbPassword.Text), tbPasswordQuestion.Text, tbAnswer.Text ); if (!res) throw new ArgumentException(GetMessageRaw("ExceptionText.ChangeOfSecretQuestionAndAnswerFailed")); } if (hfIsLockedOut.Value == "Y" && !cbIsLockedOut.Checked) if (!user.UnlockUser()) throw new ArgumentException(GetMessageRaw("ExceptionText.DeblockingOfUserFailed")); if (currentUserCanModifyUser && rolesToModify.Length > 0) { var filter = new BXFormFilter( new BXFormFilterItem("Active", true, BXSqlFilterOperators.Equal) ); if (rolesToModify.Length > 1 || rolesToModify[0] != 0) filter.Add(new BXFormFilterItem("Id", rolesToModify, BXSqlFilterOperators.In)); BXRoleCollection rolesTmp = BXRoleManager.GetList( filter, new BXOrderBy_old("RoleName", "Asc") ); foreach (BXRole roleTmp in rolesTmp) { Control cntrl = WalkThrowControlsSearch(Form, String.Format("tbCheck_{0}", roleTmp.RoleId)); bool cb = (cntrl as CheckBox).Checked; cntrl = WalkThrowControlsSearch(Form, String.Format("tbCheck_{0}_old", roleTmp.RoleId)); bool cbOld = ((cntrl as HiddenField).Value == "Y"); cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveFrom_{0}", roleTmp.RoleId)); string from = (cntrl as TextBox).Text; cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveFrom_{0}_old", roleTmp.RoleId)); string fromOld = (cntrl as HiddenField).Value; cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveTo_{0}", roleTmp.RoleId)); string to = (cntrl as TextBox).Text; cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveTo_{0}_old", roleTmp.RoleId)); string toOld = (cntrl as HiddenField).Value; if (cb && (!cbOld || !from.Equals(fromOld, StringComparison.InvariantCultureIgnoreCase) || !to.Equals(toOld, StringComparison.InvariantCultureIgnoreCase))) { if (cbOld) user.RemoveFromRole(roleTmp.RoleName); user.AddToRole(roleTmp.RoleName, from, to); } else { if (!cb && cbOld) user.RemoveFromRole(roleTmp.RoleName); } } } //BXCustomEntityManager.SaveEntity("user", user.UserId, CustomFieldList1.Save()); return true; } catch (BXEventException e) { foreach (string s in e.Messages) userValidationSummary.AddErrorMessage(s/*, "vgInnerForm", "tbUserName"*/); } catch (Exception e) { userValidationSummary.AddErrorMessage(e.Message/*, "vgInnerForm", "tbUserName"*/); } return false; }
protected void Page_Load(object sender, EventArgs e) { ((BXAdminMasterPage)Page.Master).Title = Page.Title; if (userId > 0) BXRoleManager.SynchronizeProviderUserRoles(user.UserName, user.ProviderName); var filter = new BXFormFilter( new BXFormFilterItem("Active", true, BXSqlFilterOperators.Equal) ); var roles = userId > 0 ? rolesToViewAndModify : rolesToCreate; if (roles.Length != 1 || roles[0] != 0) filter.Add(new BXFormFilterItem("Id", roles, BXSqlFilterOperators.In)); BXRoleCollection rolesTmp = BXRoleManager.GetList( filter, new BXOrderBy_old("RoleName", "Asc") ); foreach (int i in new[] { 1, 3, 2 }) { var r = rolesTmp.Find(x => x.RoleId == i); if (r != null) { rolesTmp.Remove(r); rolesTmp.Insert(0, r); } } foreach (BXRole roleTmp in rolesTmp) { HtmlTableRow r1 = new HtmlTableRow(); r1.VAlign = "top"; HtmlTableCell c1 = new HtmlTableCell(); CheckBox cb = new CheckBox(); cb.ID = String.Format("tbCheck_{0}", roleTmp.RoleId.ToString()); cb.Checked = false; c1.Controls.Add(cb); HiddenField hf = new HiddenField(); hf.ID = String.Format("tbCheck_{0}_old", roleTmp.RoleId.ToString()); hf.Value = "N"; c1.Controls.Add(hf); r1.Cells.Add(c1); c1 = new HtmlTableCell(); c1.InnerHtml = String.Format("<a href=\"AuthRolesEdit.aspx?name={0}\">{1}</a>", Server.UrlEncode(roleTmp.RoleName), Server.HtmlEncode(roleTmp.Title)); r1.Cells.Add(c1); c1 = new HtmlTableCell(); c1.Align = "center"; c1.Style["padding-right"] = "10px"; c1.Style["padding-left"] = "10px"; TextBox tb1 = new TextBox(); tb1.ID = String.Format("tbActiveFrom_{0}", roleTmp.RoleId.ToString()); c1.InnerHtml = "c "; c1.Controls.Add(tb1); hf = new HiddenField(); hf.ID = String.Format("tbActiveFrom_{0}_old", roleTmp.RoleId.ToString()); hf.Value = ""; c1.Controls.Add(hf); r1.Cells.Add(c1); c1 = new HtmlTableCell(); c1.Align = "center"; tb1 = new TextBox(); tb1.ID = String.Format("tbActiveTo_{0}", roleTmp.RoleId.ToString()); c1.InnerHtml = string.Format("{0} ", GetMessage("TabCellInnerHtml.To")); c1.Controls.Add(tb1); hf = new HiddenField(); hf.ID = String.Format("tbActiveTo_{0}_old", roleTmp.RoleId.ToString()); hf.Value = ""; c1.Controls.Add(hf); r1.Cells.Add(c1); tblRoles.Rows.Add(r1); } if (!Page.IsPostBack) LoadData(); if (userId > 0) { if (!missingProvider) { trPasswordQuestion.Style["display"] = (Membership.Providers[user.ProviderName].RequiresQuestionAndAnswer ? "" : "none"); trPasswordAnswer.Style["display"] = (Membership.Providers[user.ProviderName].RequiresQuestionAndAnswer ? "" : "none"); } else { trPasswordQuestion.Style["display"] = "none"; trPasswordAnswer.Style["display"] = "none"; trPassword.Style["display"] = "none"; trNewPassword.Style["display"] = "none"; trNewPasswordConf.Style["display"] = "none"; } } else { if (!String.IsNullOrEmpty(ddProviderName.SelectedValue)) { trPasswordQuestion.Style["display"] = (Membership.Providers[(ddProviderName.SelectedValue.Equals(GetMessageRaw("String.InnerProvider"), StringComparison.InvariantCultureIgnoreCase) ? "BXSqlMembershipProvider" : ddProviderName.SelectedValue)].RequiresQuestionAndAnswer ? "" : "none"); trPasswordAnswer.Style["display"] = (Membership.Providers[(ddProviderName.SelectedValue.Equals(GetMessageRaw("String.InnerProvider"), StringComparison.InvariantCultureIgnoreCase) ? "BXSqlMembershipProvider" : ddProviderName.SelectedValue)].RequiresQuestionAndAnswer ? "" : "none"); } else { trPasswordQuestion.Style["display"] = (Membership.Provider.RequiresQuestionAndAnswer ? "" : "none"); trPasswordAnswer.Style["display"] = (Membership.Provider.RequiresQuestionAndAnswer ? "" : "none"); } } DeleteUserSeparator.Visible = DeleteUserButton.Visible = userId > 0 && currentUserCanDeleteUser; AddUserSeparator.Visible = AddUserButton.Visible = userId > 0 && currentUserCanCreateUser; BXTabControl1.ShowSaveButton = BXTabControl1.ShowApplyButton = (userId <= 0 && currentUserCanCreateUser) || (userId > 0 && (currentUserCanModifyUser || currentUserCanModifySelfUser)); }
private bool CreateUser() { try { if (!currentUserCanCreateUser) throw new Exception(GetMessageRaw("ExceptionText.YouDontHaveRightsToCreateNewUser")); DateTime birthdayDate; DateTime.TryParse(tbBirthdayDate.Text, out birthdayDate); string providerNameTmp = ddProviderName.SelectedValue; user = new BXUser(BXTextEncoder.EmptyTextEncoder); user.UserName = tbUserName.Text; user.ProviderName = providerNameTmp; user.Password = tbNewPassword.Text; user.Email = tbEmail.Text; if (Membership.Providers[providerNameTmp].RequiresQuestionAndAnswer) { user.PasswordQuestion = tbPasswordQuestion.Text; user.PasswordAnswer = tbAnswer.Text; } user.IsApproved = cbIsApproved.Checked; user.DisplayName = tbDisplayName.Text; user.FirstName = tbFirstName.Text; user.SecondName = tbSecondName.Text; user.LastName = tbLastName.Text; user.SiteId = ddlSite.SelectedValue; user.BirthdayDate = birthdayDate; user.Comment = tbComment.Text; user.Gender = Enum.IsDefined(typeof(BXUserGender), ddlGender.SelectedValue) ? (BXUserGender)Enum.Parse(typeof(BXUserGender), ddlGender.SelectedValue) : BXUserGender.Unknown; user.CustomValues.Override(CustomFieldList1.Save()); BXFile f = SaveFile(); if (f != null) user.ImageId = f.Id; try { try { user.Create(); } catch (MembershipCreateUserException ex) { throw new Exception(GetErrorMessage(ex.StatusCode), ex); } } catch { user = null; if (f != null) f.Delete(); throw; } userId = user.UserId; hfUserId.Value = userId.ToString(); if (rolesToCreate.Length > 0) { var filter = new BXFormFilter( new BXFormFilterItem("Active", true, BXSqlFilterOperators.Equal) ); if (rolesToCreate.Length > 1 || rolesToCreate[0] != 0) filter.Add(new BXFormFilterItem("Id", rolesToCreate, BXSqlFilterOperators.In)); BXRoleCollection rolesTmp = BXRoleManager.GetList( filter, new BXOrderBy_old("RoleName", "Asc") ); foreach (BXRole roleTmp in rolesTmp) { Control cntrl = WalkThrowControlsSearch(Form, String.Format("tbCheck_{0}", roleTmp.RoleId.ToString())); bool cb = (cntrl as CheckBox).Checked; cntrl = WalkThrowControlsSearch(Form, String.Format("tbCheck_{0}_old", roleTmp.RoleId.ToString())); bool cbOld = ((cntrl as HiddenField).Value == "Y"); cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveFrom_{0}", roleTmp.RoleId.ToString())); string from = (cntrl as TextBox).Text; cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveFrom_{0}_old", roleTmp.RoleId.ToString())); string fromOld = (cntrl as HiddenField).Value; cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveTo_{0}", roleTmp.RoleId.ToString())); string to = (cntrl as TextBox).Text; cntrl = WalkThrowControlsSearch(Form, String.Format("tbActiveTo_{0}_old", roleTmp.RoleId.ToString())); string toOld = (cntrl as HiddenField).Value; if (cb && (!cbOld || !from.Equals(fromOld, StringComparison.InvariantCultureIgnoreCase) || !to.Equals(toOld, StringComparison.InvariantCultureIgnoreCase))) { if (cbOld) user.RemoveFromRole(roleTmp.RoleName); user.AddToRole(roleTmp.RoleName, from, to); } else { if (!cb && cbOld) user.RemoveFromRole(roleTmp.RoleName); } } } //BXCustomEntityManager.SaveEntity(Bitrix.Security.BXUser.GetCustomFieldsKey(), user.UserId, CustomFieldList1.Save()); return true; } catch (BXEventException e) { foreach (string s in e.Messages) userValidationSummary.AddErrorMessage(s/*, "vgInnerForm", "tbUserName"*/); } catch (Exception e) { userValidationSummary.AddErrorMessage(e.Message/*, "vgInnerForm", "tbUserName"*/); } return false; }
protected void GridView1_Select(object sender, Bitrix.UI.BXSelectEventArgs e) { int startRowIndex = 0; int maximumRows = 0; if (e.PagingOptions != null) { startRowIndex = e.PagingOptions.startRowIndex; maximumRows = e.PagingOptions.maximumRows; } List<string> visibleColumnsList = new List<string>(GridView1.GetVisibleColumnsKeys()); BXFormFilter filter = new BXFormFilter(BXAdminFilter1.CurrentFilter); if ( _userId > 0 ) filter.Add(new BXFormFilterItem("UserId", _userId, BXSqlFilterOperators.Equal)); BXUserCollection collection = BXUserManager.GetList(filter, null); e.Data = new DataView(FillTable(collection, startRowIndex, visibleColumnsList)); }
BXFormFilter MakeCurrentFilter() { BXFormFilter filter = new BXFormFilter(BXAdminFilter1.CurrentFilter); filter.Add(new BXFormFilterItem("TypeId", typeId, BXSqlFilterOperators.Equal)); filter.Add(new BXFormFilterItem("CheckPermissions", new string[] { "IBlockView" }, BXSqlFilterOperators.Equal)); return filter; }
BXFormFilter MakeCurrentFilter() { BXFormFilter filter = new BXFormFilter(BXAdminFilter1.CurrentFilter); filter.Add(new BXFormFilterItem("IBlockId", iblockId, BXSqlFilterOperators.Equal)); return filter; }
protected override void LoadComponentDefinition() { List<BXParamValue> iblockTypes = new List<BXParamValue>(); BXInfoBlockTypeCollectionOld typeCollection = BXInfoBlockTypeManagerOld.GetList(null, new BXOrderBy_old("Sort", "Asc")); foreach (BXInfoBlockTypeOld t in typeCollection) iblockTypes.Add(new BXParamValue(t.TypeLang[BXLoc.CurrentLocale].Name, t.TypeId.ToString())); ParamsDefinition["IBlockTypeId"].Values = iblockTypes; BXFormFilter iblockFilter = new BXFormFilter(); if (Parameters.ContainsKey("IBlockTypeId")) { int typeId; int.TryParse(Parameters["IBlockTypeId"], out typeId); if (typeId > 0) iblockFilter.Add(new BXFormFilterItem("TypeId", typeId, BXSqlFilterOperators.Equal)); } if (!string.IsNullOrEmpty(DesignerSite)) iblockFilter.Add(new BXFormFilterItem("Site.Id", DesignerSite, BXSqlFilterOperators.Equal)); List<BXParamValue> iblocks = new List<BXParamValue>(); BXInfoBlockCollectionOld iblockCollection = BXInfoBlockManagerOld.GetList(iblockFilter, new BXOrderBy_old("Sort", "Asc")); foreach (BXInfoBlockOld b in iblockCollection) iblocks.Add(new BXParamValue(b.Name, b.IBlockId.ToString())); ParamsDefinition["IBlockId"].Values = iblocks; base.LoadComponentDefinition(); }
protected void Page_Load(object sender, EventArgs e) { Response.Buffer = true; Parameters["IBlockTypeId"] = Parameters.Get("IBlockTypeId", 0).ToString(); Parameters["IBlockId"] = Parameters.Get("IBlockId", 0).ToString(); Parameters["IBlockSectionId"] = Parameters.Get("IBlockSectionId", 0).ToString(); Parameters["ElementsCount"] = Parameters.Get("ElementsCount", 20).ToString(); Parameters["DaysCount"] = Parameters.Get("DaysCount", 0).ToString(); Parameters["RssTTL"] = Parameters.Get("RssTTL", 60).ToString(); if (!IsCached((Page.User as BXPrincipal).GetAllRoles(true))) { List<BXTemplateIBlockElement> items = new List<BXTemplateIBlockElement>(); Results["Items"] = items; if (IBlockId > 0) { BXFormFilter iblockFilter = new BXFormFilter( new BXFormFilterItem("ID", IBlockId, BXSqlFilterOperators.Equal), new BXFormFilterItem("Active", "Y", BXSqlFilterOperators.Equal) ); if (IBlockTypeId>0) iblockFilter.Add(new BXFormFilterItem("typeid", IBlockTypeId, BXSqlFilterOperators.Equal)); BXInfoBlockCollectionOld iblockCollection = BXInfoBlockManagerOld.GetList(iblockFilter, null); foreach (BXInfoBlockOld iblock in iblockCollection) { IBlock = iblock; Results["IBlockName"] = BXStringUtility.XmlEncode(IBlock.NameRaw); Results["IBlockDescription"] = BXStringUtility.XmlEncode(IBlock.DescriptionRaw); BXFormFilter elementFilter = new BXFormFilter( new BXFormFilterItem("IBlockId", iblock.IBlockId, BXSqlFilterOperators.Equal), new BXFormFilterItem("Active", "Y", BXSqlFilterOperators.Equal), new BXFormFilterItem("ActiveDate", "Y", BXSqlFilterOperators.Equal), new BXFormFilterItem("CheckPermissions", "Y", BXSqlFilterOperators.Equal) ); if (Parameters.Get<int>("DaysCount") > 0) { elementFilter.Add(new BXFormFilterItem("ActiveFromDate", DateTime.Now.AddDays(-Parameters.Get<int>("DaysCount")), BXSqlFilterOperators.Greater)); } if (IBlockSectionId > 0) { elementFilter.Add(new BXFormFilterItem("Section.Id", IBlockSectionId, BXSqlFilterOperators.Equal)); BXFormFilter sectionFilter = new BXFormFilter( new BXFormFilterItem("IBlockId", iblock.IBlockId, BXSqlFilterOperators.Equal), new BXFormFilterItem("Active", "Y", BXSqlFilterOperators.Equal), new BXFormFilterItem("ActiveGlobal", "Y", BXSqlFilterOperators.Equal), new BXFormFilterItem("ID", IBlockSectionId, BXSqlFilterOperators.Equal) ); BXInfoBlockSectionCollectionOld sectionCollection = BXInfoBlockSectionManagerOld.GetList(sectionFilter, null); if (sectionCollection.Count > 0) { IBlockSection = sectionCollection[0]; Results["IBlockSectionName"] = BXStringUtility.XmlEncode(IBlockSection.NameRaw); Results["IBlockSectionDescription"] = BXStringUtility.XmlEncode(IBlockSection.DescriptionRaw); } } // TODO: передавать сортировку из параметров BXOrderBy_old elementOrderBy = new BXOrderBy_old("ActiveFromDate", "DESC"); elementOrderBy.Add("Sort", "Asc"); elementOrderBy.Add("ID", "Desc"); BXInfoBlockElementCollectionOld elementCollection = BXInfoBlockElementManagerOld.GetList( elementFilter, elementOrderBy, null, new BXQueryParams(new BXPagingOptions(0, Parameters.Get<int>("ElementsCount"))) ); foreach (BXInfoBlockElementOld element in elementCollection) { BXTemplateIBlockElement item = new BXTemplateIBlockElement(); item.ElementId = element.ElementId; item.Code = BXStringUtility.XmlEncode(element.CodeRaw); item.IBlockId = element.IBlockId; item.Name = BXStringUtility.XmlEncode(element.NameRaw); item.Image = element.PreviewImage; item.Description = BXStringUtility.XmlEncode(element.PreviewTextRaw); string displayDate = ""; if (element.ActiveFromDate != DateTime.MinValue) displayDate = element.ActiveFromDate.ToString("r"); else displayDate = ""; item.DisplayDate = displayDate; string detailUrl = null; if (Parameters.ContainsKey("DetailUrl") && !String.IsNullOrEmpty(Parameters["DetailUrl"])) { string str = Parameters["DetailUrl"].Replace("#SITE_DIR#", BXSite.Current.Directory); str = str.Replace("#IBLOCK_ID#", iblock.IBlockId.ToString()); str = str.Replace("#SECTION_ID#", (element.Sections.Count > 0) ? element.Sections[0].ToString() : ""); str = str.Replace("#ELEMENT_ID#", element.ElementId.ToString()); Results["IBlockId"] = iblock.IBlockId; Results["SectionId"] = (element.Sections.Count > 0) ? element.Sections[0].ToString() : ""; Results["ElementId"] = element.ElementId; str = BXUri.ToRelativeUri(BXComponentManager.MakeLink(str, Results)).Replace("//", "/"); detailUrl = BXStringUtility.XmlEncode(str); } item.DetailUrl = detailUrl; items.Add(item); } } } IncludeComponentTemplate(); } }
protected void GridView1_SelectCount(object sender, BXSelectCountEventArgs e) { BXFormFilter filter = new BXFormFilter(BXAdminFilter1.CurrentFilter); if ( iblockId > 0) filter.Add(new BXFormFilterItem("IBlockId", iblockId, BXSqlFilterOperators.Equal)); e.Count = BXInfoBlockElementManagerOld.Count(filter); }
protected void GridView1_Select(object sender, Bitrix.UI.BXSelectEventArgs e) { int startRowIndex = 0; int maximumRows = 0; if (e.PagingOptions != null) { startRowIndex = e.PagingOptions.startRowIndex; maximumRows = e.PagingOptions.maximumRows; } BXOrderBy_old sortOrder = BXDatabaseHelper.ConvertOrderBy(e.SortExpression); List<string> visibleColumnsList = new List<string>(GridView1.GetVisibleColumnsKeys()); BXFormFilter filter = new BXFormFilter(BXAdminFilter1.CurrentFilter); if ( iblockId > 0 ) filter.Add(new BXFormFilterItem("IBlockId", iblockId, BXSqlFilterOperators.Equal)); BXInfoBlockElementCollectionOld collection = BXInfoBlockElementManagerOld.GetList(filter, sortOrder); e.Data = new DataView(FillTable(collection, startRowIndex, visibleColumnsList)); }