public SubscriptionsGridSelect(BXUser user,BXForumUser forumUser,string editUserToolTipText) { if (user == null) throw new ArgumentNullException("user"); if (forumUser == null) throw new ArgumentNullException("forumUser"); this.user = user; this.forumUser = forumUser; this.editUserToolTipText = editUserToolTipText; }
public override void Load(BXUser user) { if (user != null && !user.IsNew) forumUser = BXForumUser.GetById(user.UserId, BXTextEncoder.EmptyTextEncoder); if (forumUser == null) return; Posts.Text = forumUser.Posts.ToString("#,0"); Signature.Text = forumUser.Signature; OwnPostNotification.Checked = forumUser.OwnPostNotification; }
public override void Save(BXUser user, BXSqlTransaction tran) { forumUser = forumUser ?? BXForumUser.GetById(user.UserId, BXTextEncoder.EmptyTextEncoder); if (forumUser == null) { forumUser = new BXForumUser(BXTextEncoder.EmptyTextEncoder); forumUser.Id = user.UserId; } forumUser.Signature = Signature.Text; forumUser.OwnPostNotification = OwnPostNotification.Checked; forumUser.Save(tran != null ? tran.Connection : null, tran); }
public List <BXUser> GetAllUser() { IDbConnection connection; DbProviderFactory factory; GetConection(out connection, out factory); string sqlSelect = "SELECT * FROM BXUsers"; IDbCommand command = factory.CreateCommand(); command.CommandText = sqlSelect; command.Connection = connection; List <BXUser> users = new List <BXUser>(); using (connection) { connection.Open(); IDataReader reader = command.ExecuteReader(); while (reader.Read()) { BXUser user = new BXUser(); user.UserID = Int32.Parse(reader[0].ToString()); user.City = reader[1].ToString(); user.City = reader[2].ToString(); user.City = reader[3].ToString(); string tempAge = reader[4].ToString(); // -1 define : if age is null if (tempAge.Length == 0 || tempAge == null) { user.Age = -1; } else { user.Age = Int32.Parse(tempAge); } users.Add(user); } } return(users); }
public override void Load(BXUser user) { if (user == null || user.IsNew) return; blogUser = BXBlogUser.GetList( new BXFilter(new BXFilterItem(BXBlogUser.Fields.Id, BXSqlFilterOperators.Equal, user.UserId)), null, new BXSelectAdd( BXBlogUser.Fields.UserGroups, BXBlogUser.Fields.UserGroups.UserGroup, BXBlogUser.Fields.UserGroups.UserGroup.Blog.Name, BXBlogUser.Fields.UserGroups.UserGroup.Blog.IsTeam ), null, BXTextEncoder.EmptyTextEncoder ) .FirstOrDefault(); if (blogUser == null) return; foreach (var gl in blogUser.UserGroups) { var g = gl.UserGroup; if (g == null) continue; bindings.Add(new BindingInfo { BlogGroup = g, Editable = g.Blog != null && g.Blog.IsTeam && g.Type == BXBlogUserGroupType.UserDefined, IsAuto = gl.IsAuto }); } bindings.Sort((a, b) => { return a.Editable.CompareTo(b.Editable); }); }
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 Page_Init(object sender, EventArgs e) { aifImage.NewImageUploadingHint = string.Format(GetMessage("Hint.ImageMaxSize"), BXConfigurationUtility.Options.User.AvatarMaxWidth, BXConfigurationUtility.Options.User.AvatarMaxHeight); userId = base.GetRequestInt("id"); if (userId > 0) hfUserId.Value = userId.ToString(); Int32.TryParse(hfUserId.Value, out userId); if (userId > 0) { BXUserCollection userCol = Bitrix.Security.BXUser.GetList( new BXFilter(new BXFilterItem(Bitrix.Security.BXUser.Fields.UserId, BXSqlFilterOperators.Equal, userId)), null, new BXSelectAdd(Bitrix.Security.BXUser.Fields.CustomFields.DefaultFields), null, BXTextEncoder.EmptyTextEncoder ); if ((user = userCol.Count > 0 ? userCol[0] : null) == null) { userId = 0; hfUserId.Value = userId.ToString(); } } currentUserCanModifySelfUser = userId > 0 && ((this.BXUser.Identity as BXIdentity).Id == userId) && this.BXUser.IsCanOperate(BXRoleOperation.Operations.UserModifySelf); if (userId > 0) { if (Membership.Providers[user.ProviderName] == null) missingProvider = true; userRoles = (from r in user.GetRoles() orderby r.RoleId select r.RoleId).Distinct().ToArray(); rolesToView = GetRoleIds(BXRoleOperation.Operations.UserView); if (!currentUserCanModifySelfUser && !CheckRoles(rolesToView)) BXAuthentication.AuthenticationRequired(); } else { userRoles = new int[0]; rolesToCreate = GetRoleIds(BXRoleOperation.Operations.UserCreate); if (!CheckRoles(rolesToCreate)) BXAuthentication.AuthenticationRequired(); } rolesToCreate = rolesToCreate ?? GetRoleIds(BXRoleOperation.Operations.UserCreate); rolesToModify = rolesToModify ?? GetRoleIds(BXRoleOperation.Operations.UserModify); rolesToView = rolesToView ?? GetRoleIds(BXRoleOperation.Operations.UserView); rolesToDelete = rolesToDelete ?? GetRoleIds(BXRoleOperation.Operations.UserDelete); rolesToViewAndModify = (rolesToView.Length == 1 && rolesToView[0] == 0 || rolesToModify.Length == 1 && rolesToModify[0] == 0) ? new[] { 0 } : rolesToView.Union(rolesToModify).OrderBy(x => x).Distinct().ToArray(); currentUserCanModifyUser = CheckRoles(rolesToModify); currentUserCanCreateUser = CheckRoles(rolesToCreate); currentUserCanDeleteUser = CheckRoles(rolesToDelete); IBXCustomFieldList fl = CustomFieldList1 as IBXCustomFieldList; if (user != null) fl.Load(user.CustomValues); #region Load Profile Extensions profileEditors = new List<BXUserProfileAdminFacade>(); int index = BXTabControl1.Tabs.IndexOf(NotesTab); foreach (BXUserProfileExtensionProvider provider in Bitrix.Security.BXUser.GetProfileExtensionProviders()) { BXUserProfileAdminFacade facade = provider.CreateAdminFacade(); if (facade == null) continue; profileEditors.Add(facade); ExtensionTab.Visible = true; if (facade.EditorControl != null) ExtensionTab.Controls.Add(facade.EditorControl); facade.SetValidationGroup(BXTabControl1.ValidationGroup); } #endregion PrepareForInsertScript(); }
protected void LoginButton_Click(object sender, EventArgs e) { if (phonenumber.Text.Trim() != "") { int smsCode = 0; CheckNumberResult res = CheckNumber(out smsCode); if (res == CheckNumberResult.Known) { if (smsCode.ToString() == password.Text.Trim()) { int passcode = new Random().Next(100000, 999999); try { //необходимо создать пользователя и авторизовать его BXUser user = new BXUser(); //BXUserManager.Create(phonenumber.Text.Trim(), "BXSqlMembershipProvider", out status); user.IsApproved = true; user.UserName = phonenumber.Text.Trim(); user.PasswordAnswer = "volotour"; user.Password = passcode.ToString(); user.ProviderName = "BXSqlMembershipProvider"; user.Email = phonenumber.Text.Trim() + "@volotour.ru"; user.Save(); Volotour.PersonalOffice.PersonalOfficeModule.sendsms("c79166104232", "ltkmaby123", phonenumber.Text, "Ваш пароль для volotour.ru " + passcode.ToString() + "\r\nРекомендуется сменить пароль!", true); //Активируем профиль CustomerProfilesCollection list = BXEntity<CustomerProfiles, CustomerProfilesCollection, CustomerProfiles.Scheme>.GetList( new BXFilter(new IBXFilterItem[1] { (IBXFilterItem) new BXFilterItem(BXEntity<CustomerProfiles, CustomerProfilesCollection, CustomerProfiles.Scheme>.Fields.login, BXSqlFilterOperators.Equal, (object) phonenumber.Text.Trim()) }), new BXOrderBy(new BXOrderByPair[1] { new BXOrderByPair(BXEntity<CustomerProfiles, CustomerProfilesCollection, CustomerProfiles.Scheme>.Fields.registration_date, BXOrderByDirection.Asc) })); if (list.Count() > 0) { CustomerProfiles cp = list[0]; cp.active = true; cp.Save(); } AuthUser(phonenumber.Text.Trim(), passcode.ToString()); } catch (Exception ex) { hasErrors = true; LastError = "У нас что то сломалось. Уже чиним. (" + ex.Message + ")"; } } else { WrongSmsCode = true; hasErrors = true; LastError = "Неверный код подтверждения!"; } } else { // Авторизовываем пользователя по логину - телефону AuthUser(phonenumber.Text.Trim(), password.Text); } } else { hasErrors = true; LastError = "Не введен номер!"; } ErrorForm.Visible = hasErrors; ErrorMessage.Text = LastError; //changeform(res); }
protected void SendSMSButton_Click(object sender, EventArgs e) { if (CheckNumber() == CheckNumberResult.Registered) { BXUserCollection list = BXEntity<BXUser, BXUserCollection, BXUser.Scheme>.GetList( new BXFilter(new IBXFilterItem[1] { (IBXFilterItem) new BXFilterItem(BXEntity<BXUser, BXUserCollection, BXUser.Scheme>.Fields.UserName, BXSqlFilterOperators.Equal, (object) phonenumber.Text.Trim()) }), new BXOrderBy(new BXOrderByPair[1] { new BXOrderByPair(BXEntity<BXUser, BXUserCollection, BXUser.Scheme>.Fields.UserName, BXOrderByDirection.Asc) })); if (list.Count() > 0) { try { int passcode = new Random().Next(100000, 999999); BXUser duser = list[0]; //duser.ResetPassword(null, "volotour", passcode.ToString()); //duser.Save(); duser.Delete(); BXUser user = new BXUser(); user.IsApproved = true; user.UserName = phonenumber.Text.Trim(); user.Password = passcode.ToString(); user.ProviderName = "BXSqlMembershipProvider"; user.Email = phonenumber.Text.Trim() + "@volotour.ru"; user.Save(); Volotour.PersonalOffice.PersonalOfficeModule.sendsms("c79166104232", "ltkmaby123", phonenumber.Text, "Ваш новый пароль для volotour.ru " + passcode.ToString() + "\r\nРекомендуется сменить пароль!", true); SmsMessagePanel.Visible = true; SendSMSButtonPanel.Visible = false; } catch (Exception ex) { hasErrors = true; LastError = ex.Message; } } } else { hasErrors = true; LastError = "Номер не зарегистрирован"; } ErrorForm.Visible = hasErrors; ErrorMessage.Text = LastError; }
public override void Save(BXUser user, BXSqlTransaction tran) { if (blogUser == null) { blogUser = BXBlogUser.GetList( new BXFilter(new BXFilterItem(BXBlogUser.Fields.Id, BXSqlFilterOperators.Equal, user.UserId)), null, null, new BXQueryParams { Transaction = tran }, BXTextEncoder.EmptyTextEncoder ) .FirstOrDefault(); } if (blogUser == null) { blogUser = new BXBlogUser(BXTextEncoder.EmptyTextEncoder); blogUser.Id = user.UserId; } var groups = Request.Form.GetValues(UniqueID + "$group"); var blogs = Request.Form.GetValues(UniqueID + "$blog"); var autos = Request.Form.GetValues(UniqueID + "$auto"); var newBindings = new List<BindingInfo>(); if (groups != null && groups.Length > 0) { for (int i = 0; i < groups.Length; i++) { int id; if (!int.TryParse(groups[i], out id) || id <= 0) continue; var group = BXBlogUserGroup.GetList( new BXFilter(new BXFilterItem(BXBlogUserGroup.Fields.Id, BXSqlFilterOperators.Equal, id)), null, new BXSelectAdd(BXBlogUserGroup.Fields.Blog.Name), new BXQueryParams { AllowPaging = true, PagingStartIndex = 0, PagingRecordCount = 1, Transaction = tran }, BXTextEncoder.EmptyTextEncoder ) .FirstOrDefault(); if (group == null) continue; if (group.BlogId <= 0 || !Blogs.Exists(x => x.Id == group.BlogId) || group.Type != BXBlogUserGroupType.UserDefined) { var b = bindings.Find(x => x.BlogGroup.Id == id); if (b != null && !newBindings.Exists(x => x.BlogGroup.Id == group.Id)) newBindings.Add(new BindingInfo { BlogGroup = group, Editable = false, IsAuto = b.IsAuto }); continue; } if (!newBindings.Exists(x => x.BlogGroup.Id == group.Id)) { var b = bindings.Find(x => x.BlogGroup.Id == id); newBindings.Add(new BindingInfo { BlogGroup = group, Editable = true, IsAuto = b != null && b.IsAuto && autos[i] == "true" }); } } } bindings = newBindings; blogUser.UserGroups.Clear(); blogUser.UserGroups.AddRange(bindings.ConvertAll(x => new BXBlogUser2Group(x.BlogGroup.Id))); blogUser.Save(tran != null ? tran.Connection : null, tran); }