示例#1
0
        /// <summary>
        /// The update profile_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        protected void UpdateProfile_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.HomePage.Text.IsSet())
            {
                // add http:// by default
                if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*"))
                {
                    this.HomePage.Text = "http://{0}".FormatWith(this.HomePage.Text.Trim());
                }

                if (!ValidationHelper.IsValidURL(this.HomePage.Text))
                {
                    this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.Warning);
                    return;
                }
            }

            if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.Warning);
                return;
            }

            if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_MSN"), MessageTypes.Warning);
                return;
            }

            if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.Warning);
                return;
            }

            if (this.ICQ.Text.IsSet() &&
                !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text)))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.Warning);
                return;
            }

            if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.Warning);
                return;
            }

            if (this.Google.Text.IsSet() && !ValidationHelper.IsValidURL(this.Google.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_GOOGLE"), MessageTypes.Warning);
                return;
            }

            string displayName = null;

            if (this.Get <YafBoardSettings>().EnableDisplayName &&
                this.Get <YafBoardSettings>().AllowDisplayNameModification)
            {
                // Check if name matches the required minimum length
                if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength)
                {
                    this.PageContext.AddLoadMessage(
                        this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().DisplayNameMinLength),
                        MessageTypes.Warning);

                    return;
                }

                // Check if name matches the required minimum length
                if (this.DisplayName.Text.Length > this.Get <YafBoardSettings>().UserNameMaxLength)
                {
                    this.PageContext.AddLoadMessage(
                        this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().UserNameMaxLength),
                        MessageTypes.Warning);

                    return;
                }

                if (this.DisplayName.Text.Trim() != this.UserData.DisplayName)
                {
                    if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue)
                    {
                        this.PageContext.AddLoadMessage(this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"), MessageTypes.Warning);

                        return;
                    }

                    displayName = this.DisplayName.Text.Trim();
                }
            }

            string userName = UserMembershipHelper.GetUserNameFromID(this.currentUserID);

            if (this.UpdateEmailFlag)
            {
                string newEmail = this.Email.Text.Trim();

                if (!ValidationHelper.IsValidEmail(newEmail))
                {
                    this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning);
                    return;
                }

                string userNameFromEmail = this.Get <MembershipProvider>().GetUserNameByEmail(this.Email.Text.Trim());

                if (userNameFromEmail.IsSet() && userNameFromEmail != userName)
                {
                    this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning);
                    return;
                }

                if (this.Get <YafBoardSettings>().EmailVerification)
                {
                    this.SendEmailVerification(newEmail);
                }
                else
                {
                    // just update the e-mail...
                    try
                    {
                        UserMembershipHelper.UpdateEmail(this.currentUserID, this.Email.Text.Trim());
                    }
                    catch (ApplicationException)
                    {
                        this.PageContext.AddLoadMessage(this.GetText("PROFILE", "DUPLICATED_EMAIL"), MessageTypes.Warning);

                        return;
                    }
                }
            }

            if (this.Interests.Text.Trim().Length > 400)
            {
                this.PageContext.AddLoadMessage(
                    this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400),
                    MessageTypes.Warning);

                return;
            }

            if (this.Occupation.Text.Trim().Length > 400)
            {
                this.PageContext.AddLoadMessage(
                    this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400),
                    MessageTypes.Warning);

                return;
            }

            this.UpdateUserProfile(userName);

            // vzrus: We should do it as we need to write null value to db, else it will be empty.
            // Localizer currently treats only nulls.
            object language = null;
            object culture  = this.Culture.SelectedValue;
            object theme    = this.Theme.SelectedValue;
            object editor   = this.ForumEditor.SelectedValue;

            if (this.Theme.SelectedValue.IsNotSet())
            {
                theme = null;
            }

            if (this.ForumEditor.SelectedValue.IsNotSet())
            {
                editor = null;
            }

            if (this.Culture.SelectedValue.IsNotSet())
            {
                culture = null;
            }
            else
            {
                foreach (DataRow row in
                         StaticDataHelper.Cultures()
                         .Rows.Cast <DataRow>()
                         .Where(row => culture.ToString() == row["CultureTag"].ToString()))
                {
                    language = row["CultureFile"].ToString();
                }
            }

            // save remaining settings to the DB
            LegacyDb.user_save(
                this.currentUserID,
                this.PageContext.PageBoardID,
                null,
                displayName,
                null,
                this.TimeZones.SelectedValue.ToType <int>(),
                language,
                culture,
                theme,
                editor,
                this.UseMobileTheme.Checked,
                null,
                null,
                null,
                this.DSTUser.Checked,
                this.HideMe.Checked,
                null);

            // vzrus: If it's a guest edited by an admin registry value should be changed
            DataTable dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.currentUserID, true, null, null, false);

            if (dt.Rows.Count > 0 && dt.Rows[0]["IsGuest"].ToType <bool>())
            {
                LegacyDb.registry_save("timezone", this.TimeZones.SelectedValue, this.PageContext.PageBoardID);
            }

            // clear the cache for this user...)
            this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserID));

            YafContext.Current.Get <IDataCache>().Clear();

            if (!this.adminEditMode)
            {
                YafBuildLink.Redirect(ForumPages.cp_profile);
            }
            else
            {
                this._userData = null;
                this.BindData();
            }
        }
        /// <summary>
        /// Saves the Updated Profile
        /// </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 UpdateProfile_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            var userName = UserMembershipHelper.GetUserNameFromID(this.currentUserId);

            if (this.HomePage.Text.IsSet())
            {
                // add http:// by default
                if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*"))
                {
                    this.HomePage.Text = "http://{0}".FormatWith(this.HomePage.Text.Trim());
                }

                if (!ValidationHelper.IsValidURL(this.HomePage.Text))
                {
                    this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.warning);
                    return;
                }

                if (this.UserData.NumPosts < this.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount)
                {
                    string result;

                    // Check for spam
                    if (this.Get <ISpamWordCheck>().CheckForSpamWord(this.HomePage.Text, out result))
                    {
                        // Log and Send Message to Admins
                        if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1))
                        {
                            this.Logger.Log(
                                null,
                                "Bot Detected",
                                "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user changed the profile Homepage url to: {2}"
                                .FormatWith(userName, this.currentUserId, this.HomePage.Text),
                                EventLogTypes.SpamBotDetected);
                        }
                        else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2))
                        {
                            this.Logger.Log(
                                null,
                                "Bot Detected",
                                "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user changed the profile Homepage url to: {2}, user was deleted and the name, email and IP Address are banned."
                                .FormatWith(userName, this.currentUserId, this.HomePage.Text),
                                EventLogTypes.SpamBotDetected);

                            // Kill user
                            if (!this.PageContext.CurrentForumPage.IsAdminPage)
                            {
                                var user   = UserMembershipHelper.GetMembershipUserById(this.currentUserId);
                                var userId = this.currentUserId;

                                var userIp = new CombinedUserDataHelper(user, userId).LastIP;

                                UserMembershipHelper.DeleteAndBanUser(this.currentUserId, user, userIp);
                            }
                        }
                    }
                }
            }

            if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.warning);
                return;
            }

            if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_MSN"), MessageTypes.warning);
                return;
            }

            if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.warning);
                return;
            }

            if (this.ICQ.Text.IsSet() &&
                !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text)))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.warning);
                return;
            }

            if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.warning);
                return;
            }

            if (this.Google.Text.IsSet() && !ValidationHelper.IsValidURL(this.Google.Text))
            {
                this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_GOOGLE"), MessageTypes.warning);
                return;
            }

            string displayName = null;

            if (this.Get <YafBoardSettings>().EnableDisplayName &&
                this.Get <YafBoardSettings>().AllowDisplayNameModification)
            {
                // Check if name matches the required minimum length
                if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength)
                {
                    this.PageContext.AddLoadMessage(
                        this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().DisplayNameMinLength),
                        MessageTypes.warning);

                    return;
                }

                // Check if name matches the required minimum length
                if (this.DisplayName.Text.Length > this.Get <YafBoardSettings>().UserNameMaxLength)
                {
                    this.PageContext.AddLoadMessage(
                        this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().UserNameMaxLength),
                        MessageTypes.warning);

                    return;
                }

                if (this.DisplayName.Text.Trim() != this.UserData.DisplayName)
                {
                    if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue)
                    {
                        this.PageContext.AddLoadMessage(
                            this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"),
                            MessageTypes.warning);

                        return;
                    }

                    displayName = this.DisplayName.Text.Trim();
                }
            }

            if (this.UpdateEmailFlag)
            {
                var newEmail = this.Email.Text.Trim();

                if (!ValidationHelper.IsValidEmail(newEmail))
                {
                    this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.warning);
                    return;
                }

                var userNameFromEmail = this.Get <MembershipProvider>().GetUserNameByEmail(this.Email.Text.Trim());

                if (userNameFromEmail.IsSet() && userNameFromEmail != userName)
                {
                    this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.warning);
                    return;
                }

                if (this.Get <YafBoardSettings>().EmailVerification)
                {
                    this.SendEmailVerification(newEmail);
                }
                else
                {
                    // just update the e-mail...
                    try
                    {
                        UserMembershipHelper.UpdateEmail(this.currentUserId, this.Email.Text.Trim());
                    }
                    catch (ApplicationException)
                    {
                        this.PageContext.AddLoadMessage(
                            this.GetText("PROFILE", "DUPLICATED_EMAIL"),
                            MessageTypes.warning);

                        return;
                    }
                }
            }

            if (this.Interests.Text.Trim().Length > 400)
            {
                this.PageContext.AddLoadMessage(
                    this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400),
                    MessageTypes.warning);

                return;
            }

            if (this.Occupation.Text.Trim().Length > 400)
            {
                this.PageContext.AddLoadMessage(
                    this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400),
                    MessageTypes.warning);

                return;
            }

            this.UpdateUserProfile(userName);

            // vzrus: We should do it as we need to write null value to db, else it will be empty.
            // Localizer currently treats only nulls.
            object language = null;
            object culture  = this.Culture.SelectedValue;
            object theme    = this.Theme.SelectedValue;
            object editor   = this.ForumEditor.SelectedValue;

            if (this.Theme.SelectedValue.IsNotSet())
            {
                theme = null;
            }

            if (this.ForumEditor.SelectedValue.IsNotSet())
            {
                editor = null;
            }

            if (this.Culture.SelectedValue.IsNotSet())
            {
                culture = null;
            }
            else
            {
                foreach (var row in
                         StaticDataHelper.Cultures()
                         .Rows.Cast <DataRow>()
                         .Where(row => culture.ToString() == row["CultureTag"].ToString()))
                {
                    language = row["CultureFile"].ToString();
                }
            }

            // save remaining settings to the DB
            LegacyDb.user_save(
                this.currentUserId,
                this.PageContext.PageBoardID,
                null,
                displayName,
                null,
                this.TimeZones.SelectedValue.ToType <int>(),
                language,
                culture,
                theme,
                editor,
                this.UseMobileTheme.Checked,
                null,
                null,
                null,
                this.DSTUser.Checked,
                this.HideMe.Checked,
                null);

            // vzrus: If it's a guest edited by an admin registry value should be changed
            var dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.currentUserId, true, null, null, false);

            if (dt.HasRows() && dt.Rows[0]["IsGuest"].ToType <bool>())
            {
                LegacyDb.registry_save("timezone", this.TimeZones.SelectedValue, this.PageContext.PageBoardID);
            }

            // clear the cache for this user...)
            this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserId));

            this.Get <IDataCache>().Clear();

            if (!this.PageContext.CurrentForumPage.IsAdminPage)
            {
                YafBuildLink.Redirect(ForumPages.cp_profile);
            }
            else
            {
                this.userData = null;
                this.BindData();
            }
        }
        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 profile_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void UpdateProfile_Click(object sender, EventArgs e)
        {
            if (this.HomePage.Text.IsSet())
            {
                // add http:// by default
                if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*"))
                {
                    this.HomePage.Text = "http://" + this.HomePage.Text.Trim();
                }
                if (!ValidationHelper.IsValidURL(this.HomePage.Text))
                {
                    this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "BAD_HOME"));
                    return;
                }
            }

            if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "BAD_WEBLOG"));
                return;
            }

            if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text))
            {
                this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "BAD_MSN"));
                return;
            }

            if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text))
            {
                this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "BAD_XMPP"));
                return;
            }

            if (this.ICQ.Text.IsSet() && !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsValidInt(this.ICQ.Text)))
            {
                this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "BAD_ICQ"));
                return;
            }

            string displayName = null;

            if (this.PageContext.BoardSettings.EnableDisplayName &&
                this.PageContext.BoardSettings.AllowDisplayNameModification)
            {
                if (this.DisplayName.Text.Trim().Length < 2)
                {
                    this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "INVALID_DISPLAYNAME"));
                    return;
                }

                if (this.DisplayName.Text.Trim() != this.UserData.DisplayName)
                {
                    if (this.PageContext.UserDisplayName.GetId(this.DisplayName.Text.Trim()).HasValue)
                    {
                        this.PageContext.AddLoadMessage(
                            this.PageContext.Localization.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"));

                        return;
                    }

                    displayName = this.DisplayName.Text.Trim();
                }
            }

            if (this.UpdateEmailFlag)
            {
                string newEmail = this.Email.Text.Trim();

                if (!ValidationHelper.IsValidEmail(newEmail))
                {
                    this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("PROFILE", "BAD_EMAIL"));
                    return;
                }

                if (this.PageContext.BoardSettings.EmailVerification)
                {
                    this.SendEmailVerification(newEmail);
                }
                else
                {
                    // just update the e-mail...
                    UserMembershipHelper.UpdateEmail(this.CurrentUserID, this.Email.Text.Trim());
                }
            }

            string userName = UserMembershipHelper.GetUserNameFromID(this.CurrentUserID);

            this.UpdateUserProfile(userName);

            // vzrus: We should do it as we need to write null value to db, else it will be empty.
            // Localizer currently treats only nulls.
            object language = null;
            object culture  = this.Culture.SelectedValue;
            object theme    = this.Theme.SelectedValue;

            if (string.IsNullOrEmpty(this.Theme.SelectedValue))
            {
                theme = null;
            }

            if (string.IsNullOrEmpty(this.Culture.SelectedValue))
            {
                culture = null;
            }
            else
            {
                foreach (DataRow row in
                         StaticDataHelper.Cultures().Rows.Cast <DataRow>().Where(row => culture.ToString() == row["CultureTag"].ToString()))
                {
                    language = row["CultureFile"].ToString();
                }
            }


            // save remaining settings to the DB
            DB.user_save(
                this.CurrentUserID,
                this.PageContext.PageBoardID,
                null,
                displayName,
                null,
                this.TimeZones.SelectedValue.ToType <int>(),
                language,
                culture,
                theme,
                this.UseMobileTheme.Checked,
                null,
                null,
                null,
                this.DSTUser.Checked,
                this.HideMe.Checked,
                null);

            // clear the cache for this user...
            UserMembershipHelper.ClearCacheForUserId(this.CurrentUserID);

            if (!this.AdminEditMode)
            {
                YafBuildLink.Redirect(ForumPages.cp_profile);
            }
            else
            {
                this.BindData();
            }
        }