/// <summary> /// The save user_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void SaveUser_Click([NotNull] object sender, [NotNull] EventArgs e) { if (this.Page.IsValid) { bool autoWatchTopicsEnabled = false; var value = this.rblNotificationType.SelectedValue.ToEnum <UserNotificationSetting>(); if (value == UserNotificationSetting.TopicsIPostToOrSubscribeTo) { autoWatchTopicsEnabled = true; } // save the settings... DB.user_savenotification( this.PageContext.PageUserID, this.PMNotificationEnabled.Checked, autoWatchTopicsEnabled, this.rblNotificationType.SelectedValue, this.DailyDigestEnabled.Checked); // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this.PageContext.PageUserID); // Clearing cache with old Active User Lazy Data ... this.PageContext.Cache.Remove( YafCache.GetBoardCacheKey(Constants.Cache.ActiveUserLazyData.FormatWith(this.PageContext.PageUserID))); this.PageContext.AddLoadMessage(this.GetText("SAVED_NOTIFICATION_SETTING")); } }
/// <summary> /// The delete avatar_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void DeleteAvatar_Click(object sender, EventArgs e) { DB.user_deleteavatar(this._currentUserID); // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this._currentUserID); BindData(); }
/// <summary> /// Handles click on save button. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Save_Click(object sender, EventArgs e) { // go through all roles displayed on page for (int i = 0; i < this.UserGroups.Items.Count; i++) { // get current item RepeaterItem item = this.UserGroups.Items[i]; // get role ID from it int roleID = int.Parse(((Label)item.FindControl("GroupID")).Text); // get role name string roleName = string.Empty; using (DataTable dt = DB.group_list(this.PageContext.PageBoardID, roleID)) { foreach (DataRow row in dt.Rows) { roleName = (string)row["Name"]; } } // is user supposed to be in that role? bool isChecked = ((CheckBox)item.FindControl("GroupMember")).Checked; // save user in role DB.usergroup_save(this.CurrentUserID, roleID, isChecked); // update roles if this user isn't the guest if (!UserMembershipHelper.IsGuestUser(this.CurrentUserID)) { // get user's name string userName = UserMembershipHelper.GetUserNameFromID(this.CurrentUserID); // add/remove user from roles in membership provider if (isChecked && !RoleMembershipHelper.IsUserInRole(userName, roleName)) { RoleMembershipHelper.AddUserToRole(userName, roleName); } else if (!isChecked && RoleMembershipHelper.IsUserInRole(userName, roleName)) { RoleMembershipHelper.RemoveUserFromRole(userName, roleName); } // Clearing cache with old permisssions data... this.PageContext.Cache.Remove(YafCache.GetBoardCacheKey(Constants.Cache.ActiveUserLazyData.FormatWith(this.CurrentUserID))); } } // update forum moderators cache just in case something was changed... this.PageContext.Cache.Remove(YafCache.GetBoardCacheKey(Constants.Cache.ForumModerators)); // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this.CurrentUserID); this.BindData(); }
/// <summary> /// The page_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Load(object sender, EventArgs e) { PageContext.QueryIDs = new QueryStringIDHelper("u"); if (this._adminEditMode && PageContext.IsAdmin && PageContext.QueryIDs.ContainsKey("u")) { this._currentUserID = (int)PageContext.QueryIDs["u"]; } else { this._currentUserID = PageContext.PageUserID; } if (!IsPostBack) { // check if it's a link from the avatar picker if (Request.QueryString.GetFirstOrDefault("av") != null) { // save the avatar right now... DB.user_saveavatar( this._currentUserID, "{0}{1}/{2}".FormatWith(YafForumInfo.ForumBaseUrl, YafBoardFolders.Current.Avatars, this.Request.QueryString.GetFirstOrDefault("av")), null, null); // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this._currentUserID); } this.UpdateRemote.Text = PageContext.Localization.GetText("COMMON", "UPDATE"); this.UpdateUpload.Text = PageContext.Localization.GetText("COMMON", "UPDATE"); this.Back.Text = PageContext.Localization.GetText("COMMON", "BACK"); this.NoAvatar.Text = PageContext.Localization.GetText("CP_EDITAVATAR", "NOAVATAR"); this.DeleteAvatar.Text = PageContext.Localization.GetText("CP_EDITAVATAR", "AVATARDELETE"); this.DeleteAvatar.Attributes["onclick"] = "return confirm('{0}?')".FormatWith(this.PageContext.Localization.GetText("CP_EDITAVATAR", "AVATARDELETE")); string addAdminParam = string.Empty; if (this._adminEditMode) { addAdminParam = string.Format("u={0}", this._currentUserID); } this.OurAvatar.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.avatar, addAdminParam); this.OurAvatar.Text = PageContext.Localization.GetText("CP_EDITAVATAR", "OURAVATAR_SELECT"); this.noteRemote.Text = PageContext.Localization.GetTextFormatted("NOTE_REMOTE", PageContext.BoardSettings.AvatarWidth.ToString(), PageContext.BoardSettings.AvatarHeight.ToString()); this.noteLocal.Text = PageContext.Localization.GetTextFormatted("NOTE_LOCAL", PageContext.BoardSettings.AvatarWidth.ToString(), PageContext.BoardSettings.AvatarHeight, (PageContext.BoardSettings.AvatarSize / 1024).ToString()); } BindData(); }
/// <summary> /// The remote update_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void RemoteUpdate_Click(object sender, EventArgs e) { if (this.Avatar.Text.Length > 0 && !this.Avatar.Text.StartsWith("http://")) { this.Avatar.Text = "http://" + this.Avatar.Text; } // update DB.user_saveavatar(this._currentUserID, this.Avatar.Text.Trim(), null, null); // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this._currentUserID); // clear the URL out... this.Avatar.Text = string.Empty; BindData(); }
/// <summary> /// The save_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Save_Click(object sender, EventArgs e) { // Update the Membership if (!this.IsGuestX.Checked) { MembershipUser user = UserMembershipHelper.GetUser(this.Name.Text.Trim()); if (this.Email.Text.Trim() != user.Email) { // update the e-mail here too... user.Email = this.Email.Text.Trim(); } // Update IsApproved user.IsApproved = this.IsApproved.Checked; PageContext.CurrentMembership.UpdateUser(user); } else { if (!this.IsApproved.Checked) { PageContext.AddLoadMessage("The Guest user must be marked as Approved or your forum will be unstable."); return; } } var userFlags = new UserFlags { IsHostAdmin = this.IsHostAdminX.Checked, IsGuest = this.IsGuestX.Checked, IsCaptchaExcluded = this.IsCaptchaExcluded.Checked, IsActiveExcluded = this.IsExcludedFromActiveUsers.Checked, IsApproved = this.IsApproved.Checked }; DB.user_adminsave(this.PageContext.PageBoardID, this.CurrentUserID, this.Name.Text.Trim(), this.DisplayName.Text.Trim(), this.Email.Text.Trim(), userFlags.BitValue, this.RankID.SelectedValue); UserMembershipHelper.ClearCacheForUserId(this.CurrentUserID); BindData(); }
private void SetLanguageFile(string filename) { string lang = Utils.GetCurrentLanguage(); if (lang != filename) { //gem i cookie HttpCookie languageCookie = new HttpCookie("UserLanguage"); languageCookie["File"] = filename; languageCookie.Expires = DateTime.Now.AddMonths(3); Response.Cookies.Add(languageCookie); //gem setting i brugerdb MembershipUser user = Membership.GetUser(); if (user != null) { string culture = Utils.GetCurrentCulture(filename); string sqlUpdateLanguage = string.Format("UPDATE yaf_User SET LanguageFile='{0}', Culture='{1}' WHERE Name='{2}'", filename, culture, user.UserName); string connString = ConfigurationManager.ConnectionStrings["yafnet"].ConnectionString; SqlConnection sqlConn = new SqlConnection(connString); try { SqlCommand updateLangCommand = new SqlCommand(sqlUpdateLanguage, sqlConn); updateLangCommand.Connection.Open(); updateLangCommand.ExecuteNonQuery(); } finally { sqlConn.Close(); } UserMembershipHelper.ClearCacheForUserId(UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey)); } //set aktiv som current default. Brugt hvis der ikke er en bruger YafContext.Current.BoardSettings.Language = filename; Response.Redirect(Request.RawUrl); } }
/// <summary> /// The upload update_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void UploadUpdate_Click(object sender, EventArgs e) { if (this.File.PostedFile == null || this.File.PostedFile.FileName.Trim().Length <= 0 || this.File.PostedFile.ContentLength <= 0) { return; } long x = PageContext.BoardSettings.AvatarWidth; long y = PageContext.BoardSettings.AvatarHeight; int nAvatarSize = PageContext.BoardSettings.AvatarSize; Stream resized = null; try { using (Image img = Image.FromStream(this.File.PostedFile.InputStream)) { if (img.Width > x || img.Height > y) { PageContext.AddLoadMessage(this.PageContext.Localization.GetText("CP_EDITAVATAR", "WARN_TOOBIG").FormatWith(x, y)); PageContext.AddLoadMessage(this.PageContext.Localization.GetText("CP_EDITAVATAR", "WARN_SIZE").FormatWith(img.Width, img.Height)); PageContext.AddLoadMessage(PageContext.Localization.GetText("CP_EDITAVATAR", "WARN_RESIZED")); double newWidth = img.Width; double newHeight = img.Height; if (newWidth > x) { newHeight = newHeight * x / newWidth; newWidth = x; } if (newHeight > y) { newWidth = newWidth * y / newHeight; newHeight = y; } // TODO : Save an Animated Gif var bitmap = img.GetThumbnailImage((int)newWidth, (int)newHeight, null, IntPtr.Zero); resized = new MemoryStream(); bitmap.Save(resized, img.RawFormat); } // Delete old first... DB.user_deleteavatar(this._currentUserID); DB.user_saveavatar(this._currentUserID, null, resized ?? this.File.PostedFile.InputStream, this.File.PostedFile.ContentType); // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this._currentUserID); if (nAvatarSize > 0 && this.File.PostedFile.ContentLength >= nAvatarSize && resized == null) { PageContext.AddLoadMessage(this.PageContext.Localization.GetText("CP_EDITAVATAR", "WARN_BIGFILE").FormatWith(nAvatarSize)); PageContext.AddLoadMessage(this.PageContext.Localization.GetText("CP_EDITAVATAR", "WARN_FILESIZE").FormatWith(this.File.PostedFile.ContentLength)); } this.AvatarImg.ImageUrl = "{0}resource.ashx?u={1}&upd={2}".FormatWith(YafForumInfo.ForumClientFileRoot, this._currentUserID, DateTime.Now.Ticks); } } catch (Exception) { // image is probably invalid... PageContext.AddLoadMessage(PageContext.Localization.GetText("CP_EDITAVATAR", "INVALID_FILE")); } // this.BindData(); }
/// <summary> /// The save_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Save_Click(object sender, EventArgs e) { string body = this._sig.Text; // find forbidden BBcodes in signature string detectedBbCode = YafFormatMessage.BBCodeForbiddenDetector(body, this._allowedBbcodes, ','); if (!string.IsNullOrEmpty(detectedBbCode) && detectedBbCode != "ALL") { this.PageContext.AddLoadMessage( this.PageContext.Localization.GetTextFormatted("SIGNATURE_BBCODE_WRONG", detectedBbCode)); return; } if (detectedBbCode == "ALL") { this.PageContext.AddLoadMessage(this.PageContext.Localization.GetText("BBCODE_FORBIDDEN")); return; } // find forbidden HTMLTags in signature if (!this.PageContext.IsAdmin) { string detectedHtmlTag = YafFormatMessage.CheckHtmlTags(body, this._allowedHtml, ','); if (detectedHtmlTag.IsSet()) { this.PageContext.AddLoadMessage(detectedHtmlTag); return; } } // body = YafFormatMessage.RepairHtml(this,body,false); if (this._sig.Text.Length > 0) { if (this._sig.Text.Length <= this._allowedNumberOfCharacters) { DB.user_savesignature(this.CurrentUserID, this.Get <YafBadWordReplace>().Replace(body)); } else { this.PageContext.AddLoadMessage( this.PageContext.Localization.GetTextFormatted("SIGNATURE_MAX", this._allowedNumberOfCharacters)); return; } } else { DB.user_savesignature(this.CurrentUserID, DBNull.Value); } // clear the cache for this user... UserMembershipHelper.ClearCacheForUserId(this.CurrentUserID); if (this.InAdminPages) { this.BindData(); } else { this.DoRedirect(); } }
/// <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(); } }