/// <summary> /// The update user profile. /// </summary> /// <param name="userName"> /// The user name. /// </param> private void UpdateUserProfile(string userName) { YafUserProfile userProfile = YafUserProfile.GetProfile(userName); userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.MSN = this.MSN.Text.Trim(); userProfile.YIM = this.YIM.Text.Trim(); userProfile.AIM = this.AIM.Text.Trim(); userProfile.ICQ = this.ICQ.Text.Trim(); userProfile.XMPP = this.Xmpp.Text.Trim(); userProfile.Skype = this.Skype.Text.Trim(); userProfile.RealName = this.Realname.Text.Trim(); userProfile.Occupation = this.Occupation.Text.Trim(); userProfile.Interests = this.Interests.Text.Trim(); userProfile.Gender = this.Gender.SelectedIndex; userProfile.Blog = this.Weblog.Text.Trim(); if (this.PageContext.BoardSettings.EnableDNACalendar && this.datePicker.Value > DateTime.MinValue.Date) { userProfile.Birthday = this.datePicker.Value.Date; } userProfile.BlogServiceUrl = this.WeblogUrl.Text.Trim(); userProfile.BlogServiceUsername = this.WeblogUsername.Text.Trim(); userProfile.BlogServicePassword = this.WeblogID.Text.Trim(); userProfile.Save(); }
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> /// Handles the CreatedUser event of the CreateUserWizard1 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 CreateUserWizard1_CreatedUser([NotNull] object sender, [NotNull] EventArgs e) { SitecoreMembershipUser user = UserMembershipHelper.GetUser(this.CreateUserWizard1.UserName); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, this.CreateUserWizard1.UserName); var displayName = user.UserName; if (this.Get <YafBoardSettings>().EnableDisplayName) { displayName = this.CreateUserStepContainer.FindControlAs <TextBox>("DisplayName").Text.Trim(); } // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, displayName, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... YafBuildLink.RedirectInfoPage(InfoMessage.Failure); } // handle e-mail verification if needed if (this.Get <YafBoardSettings>().EmailVerification) { // get the user email var emailTextBox = (TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); var email = emailTextBox.Text.Trim(); this.Get <ISendNotification>().SendVerificationEmail(user, email, userID); } else { // Send welcome mail/pm to user this.Get <ISendNotification>().SendUserWelcomeNotification(user, userID.Value); } if (this.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... this.Get <ISendNotification>().SendRegistrationNotificationEmail(user, userID.Value); } if (this.IsPossibleSpamBot) { this.Get <ISendNotification>().SendSpamBotNotificationToAdmins(user, userID.Value); } }
/// <summary> /// Connects the user. /// </summary> /// <param name="request">The request.</param> /// <param name="parameters">The access token.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the connect was successful or not /// </returns> public bool ConnectUser(HttpRequest request, string parameters, out string message) { var googleUser = this.GetGoogleUser(request, parameters); var userGender = 0; if (googleUser.Gender.IsSet()) { switch (googleUser.Gender) { case "male": userGender = 1; break; case "female": userGender = 2; break; } } // Create User if not exists?! if (!YafContext.Current.IsGuest && !YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { // Match the Email address? if (googleUser.Email != YafContext.Current.CurrentUserData.Email) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_GOOGLENAME_NOTMATCH"); return(false); } // Update profile with google informations YafUserProfile userProfile = YafContext.Current.Profile; userProfile.Google = googleUser.ProfileURL; userProfile.GoogleId = googleUser.UserID; userProfile.Homepage = googleUser.ProfileURL; userProfile.Gender = userGender; userProfile.Save(); // save avatar LegacyDb.user_saveavatar(YafContext.Current.PageUserID, googleUser.ProfileImage, null, null); YafSingleSignOnUser.LoginSuccess(AuthService.google, null, YafContext.Current.PageUserID, false); message = string.Empty; return(true); } message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_GOOGLE_FAILED"); return(false); }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, CreateUserWizard1.UserName); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = PageContext.GetProfile(CreateUserWizard1.UserName); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... YafBuildLink.Redirect(ForumPages.info, "i=7"); } // handle e-mail verification if needed if (PageContext.BoardSettings.EmailVerification) { // get the user email TextBox emailTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); string email = emailTextBox.Text.Trim(); string hashinput = DateTime.Now.ToString() + email + Security.CreatePassword(20); string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5"); // save verification record... YAF.Classes.Data.DB.checkemail_save(userID, hash, user.Email); YafTemplateEmail verifyEmail = new YafTemplateEmail("VERIFYEMAIL"); string subject = String.Format(GetText("VERIFICATION_EMAIL_SUBJECT"), PageContext.BoardSettings.Name); verifyEmail.TemplateParams ["{link}"] = String.Format("{1}{0}", YafBuildLink.GetLinkNotEscaped(ForumPages.approve, "k={0}", hash), YafForumInfo.ServerURL); verifyEmail.TemplateParams ["{key}"] = hash; verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name; verifyEmail.TemplateParams ["{forumlink}"] = String.Format("{0}", YafForumInfo.ForumURL); verifyEmail.SendEmail(new System.Net.Mail.MailAddress(email, user.UserName), subject, true); } }
/// <summary> /// The create user wizard 1_ created user. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { MembershipUser user = UserMembershipHelper.GetUser(this.CreateUserWizard1.UserName); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, this.CreateUserWizard1.UserName); string displayName = user.UserName; if (this.PageContext.BoardSettings.EnableDisplayName) { displayName = this.CreateUserStepContainer.FindControlAs <TextBox>("DisplayName").Text.Trim(); } // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, displayName, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... YafBuildLink.RedirectInfoPage(InfoMessage.Failure); } // handle e-mail verification if needed if (this.PageContext.BoardSettings.EmailVerification) { // get the user email this.SendVerificationEmail(user, userID); } if (this.PageContext.BoardSettings.NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... this.SendRegistrationNotificationEmail(user); } }
protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e) { if (CreateUserWizard1.WizardSteps[e.CurrentStepIndex].ID == "profile") { // this is the "Profile Information" step. Save the data to their profile (+ defaults). DropDownList timeZones = ((DropDownList)FindWizardControl("TimeZones")); TextBox locationTextBox = ((TextBox)FindWizardControl("Location")); TextBox homepageTextBox = ((TextBox)FindWizardControl("Homepage")); MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName); // setup/save the profile YafUserProfile userProfile = PageContext.GetProfile(CreateUserWizard1.UserName); userProfile.Location = locationTextBox.Text.Trim(); userProfile.Homepage = homepageTextBox.Text.Trim(); userProfile.Save(); // save the time zone... YAF.Classes.Data.DB.user_save(UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey), PageContext.PageBoardID, null, null, Convert.ToInt32(timeZones.SelectedValue), null, null, null, null, null); } }
protected void UpdateProfile_Click(object sender, System.EventArgs e) { if (HomePage.Text.Length > 0 && !HomePage.Text.StartsWith("http://")) { HomePage.Text = "http://" + HomePage.Text; } if (MSN.Text.Length > 0 && !General.IsValidEmail(MSN.Text)) { PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_MSN")); return; } if (HomePage.Text.Length > 0 && !General.IsValidURL(HomePage.Text)) { PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_HOME")); return; } if (Weblog.Text.Length > 0 && !General.IsValidURL(Weblog.Text)) { PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_WEBLOG")); return; } if (ICQ.Text.Length > 0 && !General.IsValidInt(ICQ.Text)) { PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_ICQ")); return; } if (UpdateEmailFlag) { string newEmail = Email.Text.Trim(); if (!General.IsValidEmail(newEmail)) { PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_EMAIL")); return; } if (PageContext.BoardSettings.EmailVerification) { string hashinput = DateTime.Now.ToString() + Email.Text + Security.CreatePassword(20); string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5"); // Create Email YafTemplateEmail changeEmail = new YafTemplateEmail("CHANGEEMAIL"); changeEmail.TemplateParams ["{user}"] = PageContext.PageUserName; changeEmail.TemplateParams ["{link}"] = String.Format("{1}{0}\r\n\r\n", YAF.Classes.Utils.YafBuildLink.GetLinkNotEscaped(YAF.Classes.Utils.ForumPages.approve, "k={0}", hash), YafForumInfo.ServerURL); changeEmail.TemplateParams ["{newemail}"] = Email.Text; changeEmail.TemplateParams ["{key}"] = hash; changeEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name; changeEmail.TemplateParams ["{forumlink}"] = YafForumInfo.ForumURL; // save a change email reference to the db YAF.Classes.Data.DB.checkemail_save(CurrentUserID, hash, newEmail); // send a change email message... changeEmail.SendEmail(new System.Net.Mail.MailAddress(newEmail), PageContext.Localization.GetText("COMMON", "CHANGEEMAIL_SUBJECT"), true); // show a confirmation PageContext.AddLoadMessage(String.Format(PageContext.Localization.GetText("PROFILE", "mail_sent"), Email.Text)); } else { // just update the e-mail... UserMembershipHelper.UpdateEmail(CurrentUserID, Email.Text.Trim()); } } string userName = UserMembershipHelper.GetUserNameFromID(CurrentUserID); YafUserProfile userProfile = PageContext.GetProfile(userName); userProfile.Location = Location.Text.Trim(); userProfile.Homepage = HomePage.Text.Trim(); userProfile.MSN = MSN.Text.Trim(); userProfile.YIM = YIM.Text.Trim(); userProfile.AIM = AIM.Text.Trim(); userProfile.ICQ = ICQ.Text.Trim(); userProfile.Skype = Skype.Text.Trim(); userProfile.RealName = Realname.Text.Trim(); userProfile.Occupation = Occupation.Text.Trim(); userProfile.Interests = Interests.Text.Trim(); userProfile.Gender = Gender.SelectedIndex; userProfile.Blog = Weblog.Text.Trim(); userProfile.BlogServiceUrl = WeblogUrl.Text.Trim(); userProfile.BlogServiceUsername = WeblogUsername.Text.Trim(); userProfile.BlogServicePassword = WeblogID.Text.Trim(); userProfile.Save(); // save remaining settings to the DB YAF.Classes.Data.DB.user_save(CurrentUserID, PageContext.PageBoardID, null, null, Convert.ToInt32(TimeZones.SelectedValue), Language.SelectedValue, Theme.SelectedValue, OverrideDefaultThemes.Checked, null, PMNotificationEnabled.Checked); if (!AdminEditMode) { YAF.Classes.Utils.YafBuildLink.Redirect(YAF.Classes.Utils.ForumPages.cp_profile); } else { BindData(); } }
/// <summary> /// The update user profile. /// </summary> /// <param name="userName"> /// The user name. /// </param> private void UpdateUserProfile([NotNull] string userName) { YafUserProfile userProfile = YafUserProfile.GetProfile(userName); userProfile.Country = this.Country.SelectedItem != null ? this.Country.SelectedItem.Value.Trim() : string.Empty; userProfile.Region = this.Region.SelectedItem != null && this.Country.SelectedItem != null && this.Country.SelectedItem.Value.Trim().IsSet() ? this.Region.SelectedItem.Value.Trim() : string.Empty; userProfile.City = this.City.Text.Trim(); userProfile.Location = this.Location.Text.Trim(); userProfile.Homepage = this.HomePage.Text.Trim(); userProfile.MSN = this.MSN.Text.Trim(); userProfile.YIM = this.YIM.Text.Trim(); userProfile.AIM = this.AIM.Text.Trim(); userProfile.ICQ = this.ICQ.Text.Trim(); userProfile.Facebook = this.Facebook.Text.Trim(); userProfile.Twitter = this.Twitter.Text.Trim(); userProfile.Google = this.Google.Text.Trim(); userProfile.XMPP = this.Xmpp.Text.Trim(); userProfile.Skype = this.Skype.Text.Trim(); userProfile.RealName = this.Realname.Text.Trim(); userProfile.Occupation = this.Occupation.Text.Trim(); userProfile.Interests = this.Interests.Text.Trim(); userProfile.Gender = this.Gender.SelectedIndex; userProfile.Blog = this.Weblog.Text.Trim(); DateTime userBirthdate; if (this.Get <YafBoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture()) { var persianDate = new PersianDate(this.Birthday.Text); userBirthdate = PersianDateConverter.ToGregorianDateTime(persianDate); if (userBirthdate > DateTime.MinValue.Date) { userProfile.Birthday = userBirthdate.Date; } } else { DateTime.TryParse(this.Birthday.Text, this.CurrentCultureInfo, DateTimeStyles.None, out userBirthdate); if (userBirthdate > DateTime.MinValue.Date) { // Attention! This is stored in profile in the user timezone date userProfile.Birthday = userBirthdate.Date; } } userProfile.BlogServiceUrl = this.WeblogUrl.Text.Trim(); userProfile.BlogServiceUsername = this.WeblogUsername.Text.Trim(); userProfile.BlogServicePassword = this.WeblogID.Text.Trim(); try { // Sync to User Profile Mirror table while it's dirty SettingsPropertyValueCollection settingsPropertyValueCollection = userProfile.PropertyValues; LegacyDb.SetPropertyValues( PageContext.PageBoardID, UserMembershipHelper.ApplicationName(), this.currentUserID, settingsPropertyValueCollection); } catch (Exception ex) { this.Logger.Log( "Error while syncinng the User Profile", EventLogTypes.Error, this.PageContext.PageUserName, "Edit User Profile page", ex); } userProfile.Save(); }
/// <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); "); }
/// <summary> /// The create user wizard 1_ next button click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void CreateUserWizard1_NextButtonClick([NotNull] object sender, [NotNull] WizardNavigationEventArgs e) { if (this.CreateUserWizard1.WizardSteps[e.CurrentStepIndex].ID != "profile") { return; } // this is the "Profile Information" step. Save the data to their profile (+ defaults). var timeZones = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("TimeZones"); var country = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("Country"); var locationTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Location"); var homepageTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Homepage"); var dstUser = (CheckBox)this.CreateUserWizard1.FindWizardControlRecursive("DSTUser"); MembershipUser user = UserMembershipHelper.GetUser(this.CreateUserWizard1.UserName); // setup/save the profile YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName); if (country.SelectedValue != null) { userProfile.Country = country.SelectedValue; } userProfile.Location = locationTextBox.Text.Trim(); userProfile.Homepage = homepageTextBox.Text.Trim(); userProfile.Save(); // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); LegacyDb.user_save( userID: userId, boardID: this.PageContext.PageBoardID, userName: null, displayName: null, email: null, timeZone: timeZones.SelectedValue.ToType <int>(), languageFile: null, culture: null, themeFile: null, textEditor: null, useMobileTheme: null, approved: null, pmNotification: null, autoWatchTopics: null, dSTUser: dstUser.Checked, hideUser: null, notificationType: null); bool autoWatchTopicsEnabled = this.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, this.Get <YafBoardSettings>().DefaultNotificationSetting, this.Get <YafBoardSettings>().DefaultSendDigestEmail); // Clearing cache with old Active User Lazy Data ... this.Get <IRaiseEvent>().Raise(new NewUserRegisteredEvent(user, userId)); }
/// <summary> /// Creates the Google user /// </summary> /// <param name="googleUser">The Google user.</param> /// <param name="userGender">The user gender.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the login was successfully or not /// </returns> private bool CreateGoogleUser(GoogleUser googleUser, int userGender, out string message) { if (YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } // Check user for bot var spamChecker = new YafSpamCheck(); string result; var isPossibleSpamBot = false; var userIpAddress = YafContext.Current.Get <HttpRequestBase>().GetUserRealIPAddress(); // Check content for spam if (spamChecker.CheckUserForSpamBot(googleUser.UserName, googleUser.Email, userIpAddress, out result)) { YafContext.Current.Get <ILogger>().Log( null, "Bot Detected", "Bot Check detected a possible SPAM BOT: (user name : '{0}', email : '{1}', ip: '{2}', reason : {3}), user was rejected." .FormatWith(googleUser.UserName, googleUser.Email, userIpAddress, result), EventLogTypes.SpamBotDetected); if (YafContext.Current.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { // Flag user as spam bot isPossibleSpamBot = true; } else if (YafContext.Current.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { message = YafContext.Current.Get <ILocalization>().GetText("BOT_MESSAGE"); if (!YafContext.Current.Get <YafBoardSettings>().BanBotIpOnDetection) { return(false); } YafContext.Current.GetRepository <BannedIP>() .Save( null, userIpAddress, "A spam Bot who was trying to register was banned by IP {0}".FormatWith(userIpAddress), YafContext.Current.PageUserID); // Clear cache YafContext.Current.Get <IDataCache>().Remove(Constants.Cache.BannedIP); if (YafContext.Current.Get <YafBoardSettings>().LogBannedIP) { YafContext.Current.Get <ILogger>() .Log( null, "IP BAN of Bot During Registration", "A spam Bot who was trying to register was banned by IP {0}".FormatWith( userIpAddress), EventLogTypes.IpBanSet); } return(false); } } MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get <MembershipProvider>() .CreateUser( googleUser.UserName, pass, googleUser.Email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, googleUser.UserName); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(googleUser.UserName); userProfile.Google = googleUser.ProfileURL; userProfile.GoogleId = googleUser.UserID; userProfile.Homepage = googleUser.ProfileURL; userProfile.Gender = userGender; userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } if (YafContext.Current.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... YafSingleSignOnUser.SendRegistrationNotificationEmail(user, userID.Value); } if (isPossibleSpamBot) { YafSingleSignOnUser.SendSpamBotNotificationToAdmins(user, userID.Value); } // send user register notification to the user... YafContext.Current.Get <ISendNotification>() .SendRegistrationNotificationToUser(user, pass, securityAnswer, "NOTIFICATION_ON_GOOGLE_REGISTER"); // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, googleUser.UserName, googleUser.UserName, googleUser.Email, 0, null, null, true, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get <YafBoardSettings>().DefaultSendDigestEmail); // save avatar LegacyDb.user_saveavatar(userId, googleUser.ProfileImage, null, null); YafContext.Current.Get <IRaiseEvent>().Raise(new NewUserRegisteredEvent(user, userId)); YafSingleSignOnUser.LoginSuccess(AuthService.google, user.UserName, userId, true); message = string.Empty; return(true); }
/// <summary> /// Creates the facebook user /// </summary> /// <param name="facebookUser">The facebook user.</param> /// <param name="userGender">The user gender.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the login was successfully or not /// </returns> private bool CreateFacebookUser(FacebookUser facebookUser, int userGender, out string message) { if (YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get <MembershipProvider>() .CreateUser( facebookUser.UserName, pass, facebookUser.Email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, facebookUser.UserName); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(facebookUser.UserName); userProfile.Facebook = facebookUser.ProfileURL; userProfile.FacebookId = facebookUser.UserID; userProfile.Homepage = facebookUser.ProfileURL; if (facebookUser.Birthday.IsSet()) { DateTime userBirthdate; var ci = CultureInfo.CreateSpecificCulture("en-US"); DateTime.TryParse(facebookUser.Birthday, ci, DateTimeStyles.None, out userBirthdate); if (userBirthdate > DateTimeHelper.SqlDbMinTime().Date) { userProfile.Birthday = userBirthdate; } } userProfile.RealName = facebookUser.Name; userProfile.Gender = userGender; if (facebookUser.Location != null && facebookUser.Location.Name.IsSet()) { userProfile.Location = facebookUser.Location.Name; } userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } if (YafContext.Current.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... YafSingleSignOnUser.SendRegistrationNotificationEmail(user); } // send user register notification to the user... YafContext.Current.Get <ISendNotification>() .SendRegistrationNotificationToUser(user, pass, securityAnswer, "NOTIFICATION_ON_FACEBOOK_REGISTER"); // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, facebookUser.UserName, facebookUser.UserName, facebookUser.Email, facebookUser.Timezone, null, null, true, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get <YafBoardSettings>().DefaultSendDigestEmail); // save avatar LegacyDb.user_saveavatar( userId, "https://graph.facebook.com/{0}/picture".FormatWith(facebookUser.UserID), null, null); YafContext.Current.Get <IRaiseEvent>().Raise(new NewUserRegisteredEvent(user, userId)); YafSingleSignOnUser.LoginSuccess(AuthService.facebook, user.UserName, userId, true); message = string.Empty; return(true); }
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> /// Creates the or assign twitter user. /// </summary> /// <param name="twitterUser">The twitter user.</param> /// <param name="oAuth">The oAUTH.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the login was successfully or not /// </returns> private static bool CreateTwitterUser(TwitterUser twitterUser, OAuthTwitter oAuth, out string message) { if (YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } // Create User if not exists?! Doesnt work because there is no Email var email = "{0}@twitter.com".FormatWith(twitterUser.UserName); // Check user for bot /*var spamChecker = new YafSpamCheck(); * string result; * var isPossibleSpamBot = false; * * var userIpAddress = YafContext.Current.Get<HttpRequestBase>().GetUserRealIPAddress(); * * // Check content for spam * if (spamChecker.CheckUserForSpamBot(twitterUser.UserName, twitterUser.Email, userIpAddress, out result)) * { * YafContext.Current.Get<ILogger>().Log( * null, * "Bot Detected", * "Bot Check detected a possible SPAM BOT: (user name : '{0}', email : '{1}', ip: '{2}', reason : {3}), user was rejected." * .FormatWith(twitterUser.UserName, twitterUser.Email, userIpAddress, result), * EventLogTypes.SpamBotDetected); * * if (YafContext.Current.Get<YafBoardSettings>().BotHandlingOnRegister.Equals(1)) * { * // Flag user as spam bot * isPossibleSpamBot = true; * } * else if (YafContext.Current.Get<YafBoardSettings>().BotHandlingOnRegister.Equals(2)) * { * message = YafContext.Current.Get<ILocalization>().GetText("BOT_MESSAGE"); * * if (!YafContext.Current.Get<YafBoardSettings>().BanBotIpOnDetection) * { * return false; * } * * YafContext.Current.GetRepository<BannedIP>() * .Save( * null, * userIpAddress, * "A spam Bot who was trying to register was banned by IP {0}".FormatWith(userIpAddress), * YafContext.Current.PageUserID); * * // Clear cache * YafContext.Current.Get<IDataCache>().Remove(Constants.Cache.BannedIP); * * if (YafContext.Current.Get<YafBoardSettings>().LogBannedIP) * { * YafContext.Current.Get<ILogger>() * .Log( * null, * "IP BAN of Bot During Registration", * "A spam Bot who was trying to register was banned by IP {0}".FormatWith( * userIpAddress), * EventLogTypes.IpBanSet); * } * * return false; * } * }*/ // Create User if not exists?! MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get <MembershipProvider>() .CreateUser( twitterUser.UserName, pass, email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, twitterUser.UserName); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(twitterUser.UserName); userProfile.TwitterId = twitterUser.UserId.ToString(); userProfile.Twitter = twitterUser.UserName; userProfile.Homepage = twitterUser.Url.IsSet() ? twitterUser.Url : "http://twitter.com/{0}".FormatWith(twitterUser.UserName); userProfile.RealName = twitterUser.Name; userProfile.Interests = twitterUser.Description; userProfile.Location = twitterUser.Location; userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return(false); } if (YafContext.Current.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... YafSingleSignOnUser.SendRegistrationNotificationEmail(user, userID.Value); } // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); // send user register notification to the following admin users... SendRegistrationMessageToTwitterUser(user, pass, securityAnswer, userId, oAuth); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, twitterUser.UserName, null, email, 0, null, null, null, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get <YafBoardSettings>().DefaultSendDigestEmail); // save avatar if (twitterUser.ProfileImageUrl.IsSet()) { LegacyDb.user_saveavatar(userId, twitterUser.ProfileImageUrl, null, null); } LoginTwitterSuccess(true, oAuth, userId, user); message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "UPDATE_EMAIL"); return(true); }
/// <summary> /// The create user wizard 1_ next button click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e) { if (this.CreateUserWizard1.WizardSteps[e.CurrentStepIndex].ID == "profile") { // this is the "Profile Information" step. Save the data to their profile (+ defaults). var timeZones = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("TimeZones"); var locationTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Location"); var homepageTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Homepage"); var dstUser = (CheckBox)this.CreateUserWizard1.FindWizardControlRecursive("DSTUser"); MembershipUser user = UserMembershipHelper.GetUser(this.CreateUserWizard1.UserName); // setup/save the profile YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName); // Trying to consume data about user IP whereabouts /* if (_userIpLocator.Status == "OK" && String.IsNullOrEmpty(locationTextBox.Text.Trim())) * { * * if (!String.IsNullOrEmpty(_userIpLocator.CountryName)) * { * userProfile.Location += _userIpLocator.CountryName; * } * if (!String.IsNullOrEmpty(_userIpLocator.RegionName)) * { * userProfile.Location += ", " + _userIpLocator.RegionName; * } * if (!String.IsNullOrEmpty(_userIpLocator.City)) * { * userProfile.Location += ", " + _userIpLocator.City; * } * } * else * { * userProfile.Location = locationTextBox.Text.Trim(); * } */ userProfile.Location = locationTextBox.Text.Trim(); userProfile.Homepage = homepageTextBox.Text.Trim(); userProfile.Save(); // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); DB.user_save( userId, this.PageContext.PageBoardID, null, null, null, timeZones.SelectedValue.ToType <int>(), null, null, null, null, null, null, null, dstUser.Checked, null, null); bool autoWatchTopicsEnabled = this.PageContext.BoardSettings.DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... DB.user_savenotification( userId, true, autoWatchTopicsEnabled, this.PageContext.BoardSettings.DefaultNotificationSetting, PageContext.BoardSettings.DefaultSendDigestEmail); // Clearing cache with old Active User Lazy Data ... this.PageContext.Cache.Remove(YafCache.GetBoardCacheKey(Constants.Cache.ActiveUserLazyData.FormatWith(userId))); } }
/// <summary> /// Creates the or assign twitter user. /// </summary> /// <param name="twitterUser">The twitter user.</param> /// <param name="oAuth">The oAUTH.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the login was successfully or not /// </returns> private static bool CreateTwitterUser(TwitterUser twitterUser, OAuthTwitter oAuth, out string message) { if (YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } // Create User if not exists?! Doesnt work because there is no Email var email = "{0}@twitter.com".FormatWith(twitterUser.UserName); // Create User if not exists?! MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get <MembershipProvider>() .CreateUser( twitterUser.UserName, pass, email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, twitterUser.UserName); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(twitterUser.UserName); userProfile.TwitterId = twitterUser.UserId.ToString(); userProfile.Twitter = twitterUser.UserName; userProfile.Homepage = twitterUser.Url.IsSet() ? twitterUser.Url : "http://twitter.com/{0}".FormatWith(twitterUser.UserName); userProfile.RealName = twitterUser.Name; userProfile.Interests = twitterUser.Description; userProfile.Location = twitterUser.Location; userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return(false); } if (YafContext.Current.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... YafSingleSignOnUser.SendRegistrationNotificationEmail(user); } // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); // send user register notification to the following admin users... SendRegistrationMessageToTwitterUser(user, pass, securityAnswer, userId, oAuth); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, twitterUser.UserName, null, email, 0, null, null, null, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get <YafBoardSettings>().DefaultSendDigestEmail); // save avatar if (twitterUser.ProfileImageUrl.IsSet()) { LegacyDb.user_saveavatar(userId, twitterUser.ProfileImageUrl, null, null); } LoginTwitterSuccess(true, oAuth, userId, user); message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "UPDATE_EMAIL"); return(true); }
/// <summary> /// Setups the user profile. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user identifier.</param> private void SetupUserProfile(MembershipUser user, int userId) { // this is the "Profile Information" step. Save the data to their profile (+ defaults). var timeZones = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("TimeZones"); var country = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("Country"); var locationTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Location"); var homepageTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Homepage"); var dstUser = (CheckBox)this.CreateUserWizard1.FindWizardControlRecursive("DSTUser"); // setup/save the profile YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName); if (country.SelectedValue != null) { userProfile.Country = country.SelectedValue; } string result; if (this.Get <ISpamWordCheck>().CheckForSpamWord(homepageTextBox.Text.Trim(), out result)) { this.IsPossibleSpamBotInternalCheck = true; var userIpAddress = this.Get <HttpRequestBase>().GetUserRealIPAddress(); if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { // Flag user as spam bot this.IsPossibleSpamBot = true; this.SendSpamBotNotificationToAdmins(user, userId); } else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { // Kill user UserMembershipHelper.DeleteUser(userId, true); this.PageContext.AddLoadMessage(this.GetText("BOT_MESSAGE"), MessageTypes.Error); if (this.Get <YafBoardSettings>().BanBotIpOnDetection) { this.GetRepository <BannedIP>() .Save( null, userIpAddress, "A spam Bot who was trying to register was banned by IP {0}".FormatWith(userIpAddress), this.PageContext.PageUserID); // Clear cache this.Get <IDataCache>().Remove(Constants.Cache.BannedIP); if (YafContext.Current.Get <YafBoardSettings>().LogBannedIP) { this.Get <ILogger>() .Log( this.PageContext.PageUserID, "IP BAN of Bot During Registration", "A spam Bot who was trying to register was banned by IP {0}".FormatWith( userIpAddress), EventLogTypes.IpBanSet); } } } this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', email : '{1}', ip: '{2}') reason word: {3}" .FormatWith(user.UserName, this.CreateUserWizard1.Email, userIpAddress, homepageTextBox.Text.Trim()), EventLogTypes.SpamBotDetected); } if (!this.IsPossibleSpamBotInternalCheck) { return; } userProfile.Location = locationTextBox.Text.Trim(); userProfile.Homepage = homepageTextBox.Text.Trim(); userProfile.Save(); // save the time zone... LegacyDb.user_save( userID: userId, boardID: this.PageContext.PageBoardID, userName: null, displayName: null, email: null, timeZone: timeZones.SelectedValue.ToType <int>(), languageFile: null, culture: null, themeFile: null, textEditor: null, useMobileTheme: null, approved: null, pmNotification: null, autoWatchTopics: null, dSTUser: dstUser.Checked, hideUser: null, notificationType: null); bool autoWatchTopicsEnabled = this.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, this.Get <YafBoardSettings>().DefaultNotificationSetting, this.Get <YafBoardSettings>().DefaultSendDigestEmail); }
/// <summary> /// Creates the Google user /// </summary> /// <param name="googleUser">The Google user.</param> /// <param name="userGender">The user gender.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the login was successfully or not /// </returns> private bool CreateGoogleUser(GoogleUser googleUser, int userGender, out string message) { if (YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get <MembershipProvider>() .CreateUser( googleUser.UserName, pass, googleUser.Email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, googleUser.UserName); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(googleUser.UserName); userProfile.Google = googleUser.ProfileURL; userProfile.GoogleId = googleUser.UserID; userProfile.Homepage = googleUser.ProfileURL; userProfile.Gender = userGender; userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FAILED"); return(false); } if (YafContext.Current.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... YafSingleSignOnUser.SendRegistrationNotificationEmail(user, userID.Value); } // send user register notification to the user... YafContext.Current.Get <ISendNotification>() .SendRegistrationNotificationToUser(user, pass, securityAnswer, "NOTIFICATION_ON_GOOGLE_REGISTER"); // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, googleUser.UserName, googleUser.UserName, googleUser.Email, 0, null, null, true, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get <YafBoardSettings>().DefaultSendDigestEmail); // save avatar LegacyDb.user_saveavatar(userId, googleUser.ProfileImage, null, null); YafContext.Current.Get <IRaiseEvent>().Raise(new NewUserRegisteredEvent(user, userId)); YafSingleSignOnUser.LoginSuccess(AuthService.google, user.UserName, userId, true); message = string.Empty; return(true); }
/// <summary> /// DNN Profile is newer, sync YAF now /// NOTE : no need to manually sync Email Address /// </summary> /// <param name="yafUserId">The YAF user id.</param> /// <param name="yafUserProfile">The YAF user profile.</param> /// <param name="yafUserData">The YAF user data.</param> /// <param name="dnnUserInfo">The DNN user info.</param> /// <param name="portalGUID">The portal GUID.</param> /// <param name="boardSettings">The board settings.</param> private static void SyncYafProfile(int yafUserId, YafUserProfile yafUserProfile, IUserData yafUserData, UserInfo dnnUserInfo, Guid portalGUID, YafBoardSettings boardSettings) { /*var userCuluture = new YafCultureInfo * { * LanguageFile = yafUserData.LanguageFile, * Culture = yafUserData.CultureUser * }; * * if (dnnUserInfo.Profile.PreferredLocale.IsSet()) * { * CultureInfo newCulture = new CultureInfo(dnnUserInfo.Profile.PreferredLocale); * * foreach (DataRow row in * StaticDataHelper.Cultures().Rows.Cast<DataRow>().Where( * row => dnnUserInfo.Profile.PreferredLocale == row["CultureTag"].ToString() || newCulture.TwoLetterISOLanguageName == row["CultureTag"].ToString())) * { * userCuluture.LanguageFile = row["CultureFile"].ToString(); * userCuluture.Culture = row["CultureTag"].ToString(); * } * }*/ LegacyDb.user_save( yafUserId, boardSettings.BoardID, null, dnnUserInfo.DisplayName, dnnUserInfo.Email, yafUserData.TimeZone, yafUserData.LanguageFile.IsSet() ? yafUserData.LanguageFile : null, yafUserData.CultureUser, yafUserData.ThemeFile, yafUserData.TextEditor, yafUserData.UseMobileTheme, null, null, null, yafUserData.DSTUser, yafUserData.IsActiveExcluded, null); if (dnnUserInfo.Profile.FullName.IsSet()) { yafUserProfile.RealName = dnnUserInfo.Profile.FullName; } if (dnnUserInfo.Profile.Country.IsSet() && !dnnUserInfo.Profile.Country.Equals("N/A")) { var regionInfo = GetRegionInfoFromCountryName(dnnUserInfo.Profile.Country); if (regionInfo != null) { yafUserProfile.Country = regionInfo.TwoLetterISORegionName; } } if (dnnUserInfo.Profile.City.IsSet()) { yafUserProfile.City = dnnUserInfo.Profile.City; } if (dnnUserInfo.Profile.Website.IsSet()) { yafUserProfile.Homepage = dnnUserInfo.Profile.Website; } yafUserProfile.LastSyncedWithDNN = DateTime.Now; yafUserProfile.Save(); yafUserProfile.Save(); try { if (dnnUserInfo.Profile.Photo.IsSet() && !dnnUserInfo.Profile.PhotoURL.Contains("no_avatar.gif")) { SaveDnnAvatar( "fileid={0}".FormatWith(dnnUserInfo.Profile.Photo), yafUserId, portalGUID); } else { LegacyDb.user_deleteavatar(yafUserId); } } catch (Exception) { } YafContext.Current.Get <IRaiseEvent>().Raise(new UpdateUserEvent(yafUserId)); YafContext.Current.Get <IDataCache>().Clear(); }
/// <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> /// Setups the user profile. /// </summary> /// <param name="user"> /// The user. /// </param> /// <param name="userId"> /// The user identifier. /// </param> private void SetupUserProfile(SitecoreMembershipUser user, int userId) { // this is the "Profile Information" step. Save the data to their profile (+ defaults). var timeZones = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("TimeZones"); var country = (DropDownList)this.CreateUserWizard1.FindWizardControlRecursive("Country"); var locationTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Location"); var homepageTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Homepage"); var dstUser = (CheckBox)this.CreateUserWizard1.FindWizardControlRecursive("DSTUser"); // setup/save the profile YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName); if (country.SelectedValue != null) { userProfile.Country = country.SelectedValue; } string result; if (this.Get <ISpamWordCheck>().CheckForSpamWord(homepageTextBox.Text.Trim(), out result)) { this.IsPossibleSpamBotInternalCheck = true; var userIpAddress = this.Get <HttpRequestBase>().GetUserRealIPAddress(); if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { // Flag user as spam bot this.IsPossibleSpamBot = true; this.Get <ISendNotification>().SendSpamBotNotificationToAdmins(user, userId); } else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { // Kill user UserMembershipHelper.DeleteAndBanUser(userId, user, userIpAddress); this.PageContext.AddLoadMessage(this.GetText("BOT_MESSAGE"), MessageTypes.Error); } this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', email : '{1}', ip: '{2}') reason word: {3}" .FormatWith(user.UserName, this.CreateUserWizard1.Email, userIpAddress, homepageTextBox.Text.Trim()), EventLogTypes.SpamBotDetected); } if (!this.IsPossibleSpamBotInternalCheck) { userProfile.Location = locationTextBox.Text.Trim(); // add http:// by default if (!Regex.IsMatch(homepageTextBox.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*")) { homepageTextBox.Text = "http://{0}".FormatWith(homepageTextBox.Text.Trim()); } if (ValidationHelper.IsValidURL(homepageTextBox.Text)) { userProfile.Homepage = homepageTextBox.Text.Trim(); } userProfile.Save(); // save the time zone... LegacyDb.user_save( userID: userId, boardID: this.PageContext.PageBoardID, userName: null, displayName: null, email: null, timeZone: timeZones.SelectedValue.ToType <int>(), languageFile: null, culture: null, themeFile: null, textEditor: null, useMobileTheme: null, approved: null, pmNotification: null, autoWatchTopics: null, dSTUser: dstUser.Checked, hideUser: null, notificationType: null); var autoWatchTopicsEnabled = this.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, this.Get <YafBoardSettings>().DefaultNotificationSetting, this.Get <YafBoardSettings>().DefaultSendDigestEmail); } }
/// <summary> /// Connects the user. /// </summary> /// <param name="request">The request.</param> /// <param name="parameters">The parameters.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the connect was successful or not /// </returns> public bool ConnectUser(HttpRequest request, string parameters, out string message) { var oAuth = new OAuthTwitter { ConsumerKey = Config.TwitterConsumerKey, ConsumerSecret = Config.TwitterConsumerSecret }; // Get the access token and secret. oAuth.AccessTokenGet(request["oauth_token"], request["oauth_verifier"]); if (oAuth.TokenSecret.Length > 0) { var tweetAPI = new TweetAPI(oAuth); var twitterUser = tweetAPI.GetUser(); if (twitterUser.UserId > 0) { // Create User if not exists?! if (!YafContext.Current.IsGuest && !YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { // Because twitter doesnt provide the email we need to match the user name... if (twitterUser.UserName != YafContext.Current.Profile.UserName) { message = YafContext.Current.Get <ILocalization>() .GetText("LOGIN", "SSO_TWITTERNAME_NOTMATCH"); return(false); } // Update profile with twitter informations YafUserProfile userProfile = YafContext.Current.Profile; userProfile.TwitterId = twitterUser.UserId.ToString(); userProfile.Twitter = twitterUser.UserName; userProfile.Homepage = twitterUser.Url.IsSet() ? twitterUser.Url : "http://twitter.com/{0}".FormatWith(twitterUser.UserName); userProfile.RealName = twitterUser.Name; userProfile.Interests = twitterUser.Description; userProfile.Location = twitterUser.Location; userProfile.Save(); // save avatar if (twitterUser.ProfileImageUrl.IsSet()) { LegacyDb.user_saveavatar( YafContext.Current.PageUserID, twitterUser.ProfileImageUrl, null, null); } YafSingleSignOnUser.LoginSuccess(AuthService.twitter, null, YafContext.Current.PageUserID, false); message = string.Empty; return(true); } } } message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return(false); }
/// <summary> /// Connects the user. /// </summary> /// <param name="request">The request.</param> /// <param name="parameters">The access token.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the connect was successful or not /// </returns> public bool ConnectUser(HttpRequest request, string parameters, out string message) { var facebookUser = this.GetFacebookUser(request, parameters); // Check if username is null if (facebookUser.UserName.IsNotSet()) { facebookUser.UserName = facebookUser.Name; } var userGender = 0; if (facebookUser.Gender.IsSet()) { switch (facebookUser.Gender) { case "male": userGender = 1; break; case "female": userGender = 2; break; } } // Create User if not exists?! if (!YafContext.Current.IsGuest && !YafContext.Current.Get <YafBoardSettings>().DisableRegistrations) { // match the email address... if (facebookUser.Email != YafContext.Current.CurrentUserData.Email) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FACEBOOKNAME_NOTMATCH"); return(false); } // Update profile with facebook informations YafUserProfile userProfile = YafContext.Current.Profile; userProfile.Facebook = facebookUser.ProfileURL; userProfile.FacebookId = facebookUser.UserID; userProfile.Homepage = facebookUser.ProfileURL; if (facebookUser.Birthday.IsSet()) { DateTime userBirthdate; var ci = CultureInfo.CreateSpecificCulture("en-US"); DateTime.TryParse(facebookUser.Birthday, ci, DateTimeStyles.None, out userBirthdate); if (userBirthdate > DateTimeHelper.SqlDbMinTime().Date) { userProfile.Birthday = userBirthdate; } } userProfile.RealName = facebookUser.Name; userProfile.Gender = userGender; if (facebookUser.Location != null && facebookUser.Location.Name.IsSet()) { userProfile.Location = facebookUser.Location.Name; } userProfile.Save(); // save avatar LegacyDb.user_saveavatar( YafContext.Current.PageUserID, "https://graph.facebook.com/{0}/picture".FormatWith(facebookUser.UserID), null, null); YafSingleSignOnUser.LoginSuccess(AuthService.facebook, null, YafContext.Current.PageUserID, false); message = string.Empty; return(true); } message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FACEBOOK_FAILED"); return(false); }
/// <summary> /// The migrate users from <paramref name="dataTable"/>. /// </summary> /// <param name="approved"> /// The approved. /// </param> /// <param name="dataTable"> /// The dataTable. /// </param> private static void MigrateUsersFromDataTable(bool approved, [NotNull] DataTable dataTable) { // is this the Yaf membership provider? bool isYafProvider = YafContext.Current.Get <MembershipProvider>().Name == "YafMembershipProvider"; bool isLegacyYafDB = dataTable.Columns.Contains("Location"); var userRows = dataTable.AsEnumerable(); Parallel.ForEach( userRows, row => { // skip the guest user if (row.Field <bool>("IsGuest")) { return; } // validate that name and email are available... if (row["Name"].IsNullOrEmptyDBField() || row["Email"].IsNullOrEmptyDBField()) { return; } string name = row.Field <string>("Name").Trim(); string email = row.Field <string>("Email").ToLower().Trim(); // clean up the name by removing commas... name = name.Replace(",", string.Empty); // verify this user & email are not empty if (!name.IsSet() || !email.IsSet()) { return; } MembershipUser user = UserMembershipHelper.GetUser(name, false); if (user == null) { MembershipCreateStatus status = MigrateCreateUser( name, email, "Your email in all lower case", email, approved, out user); if (status != MembershipCreateStatus.Success) { YafContext.Current.Get <ILogger>() .Log(0, "MigrateUsers", "Failed to create user {0}: {1}".FormatWith(name, status)); } else { // update the YAF table with the ProviderKey -- update the provider table if this is the YAF provider... LegacyDb.user_migrate(row["UserID"], user.ProviderUserKey, isYafProvider); user.Comment = "Migrated from YetAnotherForum.NET"; YafContext.Current.Get <MembershipProvider>().UpdateUser(user); if (!isYafProvider) { /* Email generated password to user * System.Text.StringBuilder msg = new System.Text.StringBuilder(); * msg.AppendFormat( "Hello {0}.\r\n\r\n", name ); * msg.AppendFormat( "Here is your new password: {0}\r\n\r\n", password ); * msg.AppendFormat( "Visit {0} at {1}", ForumName, ForumURL ); * * YAF.Classes.Data.DB.mail_create( ForumEmail, user.Email, "Forum Upgrade", msg.ToString() ); */ } } if (isLegacyYafDB) { // copy profile data over... YafUserProfile userProfile = YafUserProfile.GetProfile(name); if (dataTable.Columns.Contains("AIM") && !row["AIM"].IsNullOrEmptyDBField()) { userProfile.AIM = row["AIM"].ToString(); } if (dataTable.Columns.Contains("YIM") && !row["YIM"].IsNullOrEmptyDBField()) { userProfile.YIM = row["YIM"].ToString(); } if (dataTable.Columns.Contains("MSN") && !row["MSN"].IsNullOrEmptyDBField()) { userProfile.MSN = row["MSN"].ToString(); } if (dataTable.Columns.Contains("ICQ") && !row["ICQ"].IsNullOrEmptyDBField()) { userProfile.ICQ = row["ICQ"].ToString(); } if (dataTable.Columns.Contains("RealName") && !row["RealName"].IsNullOrEmptyDBField()) { userProfile.RealName = row["RealName"].ToString(); } if (dataTable.Columns.Contains("Occupation") && !row["Occupation"].IsNullOrEmptyDBField()) { userProfile.Occupation = row["Occupation"].ToString(); } if (dataTable.Columns.Contains("Location") && !row["Location"].IsNullOrEmptyDBField()) { userProfile.Location = row["Location"].ToString(); } if (dataTable.Columns.Contains("Homepage") && !row["Homepage"].IsNullOrEmptyDBField()) { userProfile.Homepage = row["Homepage"].ToString(); } if (dataTable.Columns.Contains("Interests") && !row["Interests"].IsNullOrEmptyDBField()) { userProfile.Interests = row["Interests"].ToString(); } if (dataTable.Columns.Contains("Weblog") && !row["Weblog"].IsNullOrEmptyDBField()) { userProfile.Blog = row["Weblog"].ToString(); } if (dataTable.Columns.Contains("Gender") && !row["Gender"].IsNullOrEmptyDBField()) { userProfile.Gender = row["Gender"].ToType <int>(); } userProfile.Save(); } } else { // just update the link just in case... LegacyDb.user_migrate(row["UserID"], user.ProviderUserKey, false); } // setup roles for this user... using (DataTable dtGroups = LegacyDb.usergroup_list(row["UserID"])) { foreach (DataRow rowGroup in dtGroups.Rows) { AddUserToRole(user.UserName, rowGroup["Name"].ToString()); } } }); }
/// <summary> /// Import the User From the Current Table Row /// </summary> /// <param name="row"> /// The row with the User Information. /// </param> /// <param name="importCount"> /// The import Count. /// </param> /// <returns> /// Returns the Imported User Count. /// </returns> private int ImportUser(DataRow row, int importCount) { // Also Check if the Email is unique and exists if (this.Get <MembershipProvider>().RequiresUniqueEmail) { if (this.Get <MembershipProvider>().GetUserNameByEmail((string)row["Email"]) != null) { return(importCount); } } MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); var securityQuestion = "Answer is a generated Pass"; if (row.Table.Columns.Contains("Password") && !string.IsNullOrEmpty((string)row["Password"]) && row.Table.Columns.Contains("SecurityQuestion") && !string.IsNullOrEmpty((string)row["SecurityQuestion"]) && row.Table.Columns.Contains("SecurityAnswer") && !string.IsNullOrEmpty((string)row["SecurityAnswer"])) { pass = (string)row["Password"]; securityAnswer = (string)row["SecurityAnswer"]; securityQuestion = (string)row["SecurityQuestion"]; } var user = YafContext.Current.Get <MembershipProvider>().CreateUser( (string)row["Name"], pass, (string)row["Email"], this.Get <MembershipProvider>().RequiresQuestionAndAnswer ? securityQuestion : null, this.Get <MembershipProvider>().RequiresQuestionAndAnswer ? securityAnswer : null, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, (string)row["Name"]); // create the user in the YAF DB as well as sync roles... int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile((string)row["Name"]); // Add Profile Fields to User List Table. if (row.Table.Columns.Contains("RealName") && !string.IsNullOrEmpty((string)row["RealName"])) { userProfile.RealName = (string)row["RealName"]; } if (row.Table.Columns.Contains("Blog") && !string.IsNullOrEmpty((string)row["Blog"])) { userProfile.Blog = (string)row["Blog"]; } if (row.Table.Columns.Contains("Gender") && !string.IsNullOrEmpty((string)row["Gender"])) { int gender; int.TryParse((string)row["Gender"], out gender); userProfile.Gender = gender; } if (row.Table.Columns.Contains("Birthday") && !string.IsNullOrEmpty((string)row["Birthday"])) { DateTime userBirthdate; DateTime.TryParse((string)row["Birthday"], out userBirthdate); if (userBirthdate > DateTimeHelper.SqlDbMinTime()) { userProfile.Birthday = userBirthdate; } } if (row.Table.Columns.Contains("MSN") && !string.IsNullOrEmpty((string)row["MSN"])) { userProfile.MSN = (string)row["MSN"]; } if (row.Table.Columns.Contains("BlogServiceUsername") && !string.IsNullOrEmpty((string)row["BlogServiceUsername"])) { userProfile.BlogServiceUsername = (string)row["BlogServiceUsername"]; } if (row.Table.Columns.Contains("BlogServicePassword") && !string.IsNullOrEmpty((string)row["BlogServicePassword"])) { userProfile.BlogServicePassword = (string)row["BlogServicePassword"]; } if (row.Table.Columns.Contains("AIM") && !string.IsNullOrEmpty((string)row["AIM"])) { userProfile.AIM = (string)row["AIM"]; } if (row.Table.Columns.Contains("Google") && !string.IsNullOrEmpty((string)row["Google"])) { userProfile.Google = (string)row["Google"]; } if (row.Table.Columns.Contains("GoogleId") && !string.IsNullOrEmpty((string)row["GoogleId"])) { userProfile.GoogleId = (string)row["GoogleId"]; } if (row.Table.Columns.Contains("Location") && !string.IsNullOrEmpty((string)row["Location"])) { userProfile.Location = (string)row["Location"]; } if (row.Table.Columns.Contains("Country") && !string.IsNullOrEmpty((string)row["Country"])) { userProfile.Country = (string)row["Country"]; } if (row.Table.Columns.Contains("Region") && !string.IsNullOrEmpty((string)row["Region"])) { userProfile.Region = (string)row["Region"]; } if (row.Table.Columns.Contains("City") && !string.IsNullOrEmpty((string)row["City"])) { userProfile.City = (string)row["City"]; } if (row.Table.Columns.Contains("Interests") && !string.IsNullOrEmpty((string)row["Interests"])) { userProfile.Interests = (string)row["Interests"]; } if (row.Table.Columns.Contains("Homepage") && !string.IsNullOrEmpty((string)row["Homepage"])) { userProfile.Homepage = (string)row["Homepage"]; } if (row.Table.Columns.Contains("Skype") && !string.IsNullOrEmpty((string)row["Skype"])) { userProfile.Skype = (string)row["Skype"]; } if (row.Table.Columns.Contains("ICQe") && !string.IsNullOrEmpty((string)row["ICQ"])) { userProfile.ICQ = (string)row["ICQ"]; } if (row.Table.Columns.Contains("XMPP") && !string.IsNullOrEmpty((string)row["XMPP"])) { userProfile.XMPP = (string)row["XMPP"]; } if (row.Table.Columns.Contains("YIM") && !string.IsNullOrEmpty((string)row["YIM"])) { userProfile.YIM = (string)row["YIM"]; } if (row.Table.Columns.Contains("Occupation") && !string.IsNullOrEmpty((string)row["Occupation"])) { userProfile.Occupation = (string)row["Occupation"]; } if (row.Table.Columns.Contains("Twitter") && !string.IsNullOrEmpty((string)row["Twitter"])) { userProfile.Twitter = (string)row["Twitter"]; } if (row.Table.Columns.Contains("TwitterId") && !string.IsNullOrEmpty((string)row["TwitterId"])) { userProfile.TwitterId = (string)row["TwitterId"]; } if (row.Table.Columns.Contains("Facebook") && !string.IsNullOrEmpty((string)row["Facebook"])) { userProfile.Facebook = (string)row["Facebook"]; } if (row.Table.Columns.Contains("FacebookId") && !string.IsNullOrEmpty((string)row["FacebookId"])) { userProfile.FacebookId = (string)row["FacebookId"]; } userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... return(importCount); } // send user register notification to the new users this.Get <ISendNotification>().SendRegistrationNotificationToUser( user, pass, securityAnswer, "NOTIFICATION_ON_REGISTER"); // save the time zone... var userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); var isDST = false; if (row.Table.Columns.Contains("IsDST") && !string.IsNullOrEmpty((string)row["IsDST"])) { bool.TryParse((string)row["IsDST"], out isDST); } var timeZone = 0; if (row.Table.Columns.Contains("Timezone") && !string.IsNullOrEmpty((string)row["Timezone"])) { int.TryParse((string)row["Timezone"], out timeZone); } LegacyDb.user_save( userId, YafContext.Current.PageBoardID, row["Name"], row.Table.Columns.Contains("DisplayName") ? row["DisplayName"] : null, row["Email"], timeZone, row.Table.Columns.Contains("LanguageFile") ? row["LanguageFile"] : null, row.Table.Columns.Contains("Culture") ? row["Culture"] : null, row.Table.Columns.Contains("ThemeFile") ? row["ThemeFile"] : null, row.Table.Columns.Contains("TextEditor") ? row["TextEditor"] : null, null, null, null, null, isDST, null, null); var autoWatchTopicsEnabled = this.Get <YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, this.Get <YafBoardSettings>().DefaultNotificationSetting, this.Get <YafBoardSettings>().DefaultSendDigestEmail); importCount++; return(importCount); }