private static void CreateYAFUser(string sUsername, string sPassword, string email) { if (!UserMembershipHelper.UserExists(sUsername, email)) { YafMembershipProvider mb = (YafMembershipProvider)System.Web.Security.Membership.Providers["YafMembershipProvider"]; int?forumUserID = 0; if (!mb.ValidateUser(sUsername, sPassword)) { MembershipCreateStatus status; MembershipUser forumUser = mb.CreateUser(sUsername, sPassword, email, "question", "answer", true, null, out status); // create the user in the YAF DB as well as sync roles... forumUserID = RoleMembershipHelper.CreateForumUser(forumUser, 1); RoleMembershipHelper.SetupUserRoles(1, sUsername); RoleMembershipHelper.AddUserToRole(sUsername, "Registered"); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(sUsername); userProfile.Homepage = "fwd.com"; // setup their inital profile information userProfile.Save(); } else { return; } } }
/// <summary> /// The forum register_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void ForumRegister_Click([NotNull] object sender, [NotNull] EventArgs e) { if (!this.Page.IsValid) { return; } var newEmail = this.Email.Text.Trim(); var newUsername = this.UserName.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_INVALID_MAIL")); return; } if (UserMembershipHelper.UserExists(this.UserName.Text.Trim(), newEmail)) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_NAME_EXISTS")); return; } MembershipCreateStatus status; MembershipUser user = this.Get <MembershipProvider>() .CreateUser( newUsername, this.Password.Text.Trim(), newEmail, this.Question.Text.Trim(), this.Answer.Text.Trim(), !this.Get <YafBoardSettings>().EmailVerification, null, out status); if (status != MembershipCreateStatus.Success) { // error of some kind this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_ERROR_CREATE").FormatWith(status)); return; } // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, newUsername); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create profile YafUserProfile userProfile = YafUserProfile.GetProfile(newUsername); // setup their inital profile information userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.Save(); var autoWatchTopicsEnabled = this.Get <YafBoardSettings>() .DefaultNotificationSetting.Equals(UserNotificationSetting.TopicsIPostToOrSubscribeTo); // save the time zone... LegacyDb.user_save( UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey), this.PageContext.PageBoardID, null, null, null, this.TimeZones.SelectedValue.ToType <int>(), null, null, null, null, null, null, this.Get <YafBoardSettings>().DefaultNotificationSetting, autoWatchTopicsEnabled, null, null, null); if (this.Get <YafBoardSettings>().EmailVerification) { this.Get <ISendNotification>().SendVerificationEmail(user, newEmail, userID, newUsername); } LegacyDb.user_savenotification( UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey), true, autoWatchTopicsEnabled, this.Get <YafBoardSettings>().DefaultNotificationSetting, this.Get <YafBoardSettings>().DefaultSendDigestEmail); // success this.PageContext.AddLoadMessage( this.GetText("ADMIN_REGUSER", "MSG_CREATED").FormatWith(this.UserName.Text.Trim())); YafBuildLink.Redirect(ForumPages.admin_reguser); }
/// <summary> /// The create users. /// </summary> /// <param name="boardID"> /// The board id. /// </param> /// <param name="_users_Number"> /// The _users_ number. /// </param> /// <param name="_outCounter"> /// The _out counter. /// </param> /// <param name="_countLimit"> /// The _count limit. /// </param> /// <param name="_excludeCurrentBoard"> /// The _exclude current board. /// </param> /// <returns> /// The string with number of created users. /// </returns> private string CreateUsers( int boardID, int _users_Number, int _outCounter, int _countLimit, bool _excludeCurrentBoard) { int iboards; // if ( _users_Number > createCommonLimit ) _users_Number = createCommonLimit; for (iboards = 0; iboards < _countLimit; iboards++) { boardID = this.UsersBoardsList.Items[iboards].Value.ToType <int>(); int i; for (i = 0; i < this.UsersNumber.Text.Trim().ToType <int>(); i++) { this.randomGuid = Guid.NewGuid().ToString(); string newEmail = this.UserPrefixTB.Text.Trim() + this.randomGuid + "@test.info"; string newUsername = this.UserPrefixTB.Text.Trim() + this.randomGuid; if (UserMembershipHelper.UserExists(newUsername, newEmail)) { continue; } string hashinput = DateTime.UtcNow + newEmail + Security.CreatePassword(20); string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5"); MembershipCreateStatus status; MembershipUser user = this.Get <MembershipProvider>().CreateUser( newUsername, this.Password.Text.Trim(), newEmail, this.Question.Text.Trim(), this.Answer.Text.Trim(), !this.Get <YafBoardSettings>().EmailVerification, null, out status); if (status != MembershipCreateStatus.Success) { continue; } // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(boardID, newUsername); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, boardID); // create profile YafUserProfile userProfile = YafUserProfile.GetProfile(newUsername); // setup their inital profile information userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.Save(); // save the time zone... if ( !(this.UsersBoardsList.Items[iboards].Value.ToType <int>() == YafContext.Current.PageBoardID && _excludeCurrentBoard)) { LegacyDb.user_save( LegacyDb.user_get(boardID, user.ProviderUserKey), boardID, null, null, null, this.TimeZones.SelectedValue.ToType <int>(), null, null, null, null, null, null, null, null, null, null, null); _outCounter++; } } } return(_outCounter + " Users in " + iboards + " Board(s); "); }
protected void ForumRegister_Click(object sender, System.EventArgs e) { if (Page.IsValid) { string newEmail = Email.Text.Trim(); string newUsername = UserName.Text.Trim(); if (!General.IsValidEmail(newEmail)) { PageContext.AddLoadMessage("You have entered an illegal e-mail address."); return; } if (UserMembershipHelper.UserExists(UserName.Text.Trim(), newEmail)) { PageContext.AddLoadMessage("Username or email are already registered."); return; } string hashinput = DateTime.Now.ToString() + newEmail + Security.CreatePassword(20); string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5"); MembershipCreateStatus status; MembershipUser user = Membership.CreateUser(newUsername, Password.Text.Trim(), newEmail, Question.Text.Trim(), Answer.Text.Trim(), !PageContext.BoardSettings.EmailVerification, out status); if (status != MembershipCreateStatus.Success) { // error of some kind PageContext.AddLoadMessage("Membership Error Creating User: "******"VERIFYEMAIL"); verifyEmail.TemplateParams ["{link}"] = String.Format("{1}{0}", YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.approve, "k={0}", hash), YAF.Classes.Utils.YafForumInfo.ServerURL); verifyEmail.TemplateParams ["{key}"] = hash; verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name; verifyEmail.TemplateParams ["{forumlink}"] = String.Format("{0}", ForumURL); string subject = String.Format(PageContext.Localization.GetText("COMMON", "EMAILVERIFICATION_SUBJECT"), PageContext.BoardSettings.Name); verifyEmail.SendEmail(new System.Net.Mail.MailAddress(newEmail, newUsername), subject, true); } // success PageContext.AddLoadMessage(string.Format("User {0} Created Successfully.", UserName.Text.Trim())); YAF.Classes.Utils.YafBuildLink.Redirect(YAF.Classes.Utils.ForumPages.admin_reguser); } }
/// <summary> /// Handles the Click event of the ForumRegister control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void ForumRegisterClick([NotNull] object sender, [NotNull] EventArgs e) { this.Page.Validate(); if (!this.Page.IsValid) { return; } var newEmail = this.Email.Text.Trim(); var newUsername = this.UserName.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_INVALID_MAIL"), MessageTypes.danger); return; } if (UserMembershipHelper.UserExists(this.UserName.Text.Trim(), newEmail)) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_NAME_EXISTS"), MessageTypes.danger); return; } var user = this.Get <MembershipProvider>().CreateUser( newUsername, this.Password.Text.Trim(), newEmail, this.Question.Text.Trim(), this.Answer.Text.Trim(), !this.Get <BoardSettings>().EmailVerification, null, out var status); if (status != MembershipCreateStatus.Success) { // error of some kind this.PageContext.AddLoadMessage( this.GetTextFormatted("MSG_ERROR_CREATE", status), MessageTypes.danger); return; } // setup initial roles (if any) for this user RoleMembershipHelper.SetupUserRoles(BoardContext.Current.PageBoardID, newUsername); // create the user in the YAF DB as well as sync roles... var userId = RoleMembershipHelper.CreateForumUser(user, BoardContext.Current.PageBoardID); // create profile var userProfile = Utils.UserProfile.GetProfile(newUsername); // setup their initial profile information userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.Save(); var autoWatchTopicsEnabled = this.Get <BoardSettings>().DefaultNotificationSetting .Equals(UserNotificationSetting.TopicsIPostToOrSubscribeTo); // save the time zone... this.GetRepository <User>().Save( UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey), this.PageContext.PageBoardID, null, null, null, this.TimeZones.SelectedValue, null, null, null, false); if (this.Get <BoardSettings>().EmailVerification) { this.Get <ISendNotification>().SendVerificationEmail(user, newEmail, userId, newUsername); } this.GetRepository <User>().SaveNotification( UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey), true, autoWatchTopicsEnabled, this.Get <BoardSettings>().DefaultNotificationSetting.ToInt(), this.Get <BoardSettings>().DefaultSendDigestEmail); // success this.PageContext.AddLoadMessage( this.GetTextFormatted("MSG_CREATED", this.UserName.Text.Trim()), MessageTypes.success); BuildLink.Redirect(ForumPages.Admin_RegisterUser); }