/// <summary> /// 批量生成验证码 /// </summary> /// <param name="captcha">验证码帮助类</param> /// <param name="row">生成的行数</param> /// <param name="column">生成的列数</param> /// <param name="filePath">保存的图片的完整路径</param> private void BatchGenerateCaptcha(CaptchaHelper captcha, int row, int column, string filePath) { var hasChinese = captcha.Mode == CaptchaMode.Chinese || captcha.Mode == CaptchaMode.QuestionBank; int sigleWidth = captcha.StringLength * captcha.FontSize * (hasChinese ? 2 : 1); int sigleHeight = Convert.ToInt32(0.6 * captcha.FontSize + captcha.FontSize); int width = sigleWidth * column; //总图片宽度 int height = sigleHeight * row; //总图片高度 var image = new Bitmap(width, height); using Graphics graphics = Graphics.FromImage(image); graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.Clear(Color.White); for (int j = 0; j < 20; j++) { for (int i = 0; i < 10; i++) { graphics.DrawImage( captcha.GetCaptcha().Image, //生成的验证码 i * sigleWidth, //X位置 j * sigleHeight, //Y位置 sigleWidth, //单张验证码长度 sigleHeight //单张验证码高度 ); } } using FileStream stream = new(filePath, FileMode.OpenOrCreate); image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.PageBoardContext.PageForumID == 0) { this.Get <LinkBuilder>().AccessDenied(); } if (this.Get <HttpRequestBase>()["t"] == null && this.Get <HttpRequestBase>()["m"] == null && !this.PageBoardContext.ForumPostAccess) { this.Get <LinkBuilder>().AccessDenied(); } if (this.Get <HttpRequestBase>()["t"] != null && !this.PageBoardContext.ForumReplyAccess) { this.Get <LinkBuilder>().AccessDenied(); } if (this.EditMessageId.HasValue) { var editMessage = this.GetRepository <Message>().GetMessageAsTuple(this.EditMessageId.Value); if (editMessage != null) { this.ownerUserId = editMessage.Item2.UserID; if (!this.CanEditPostCheck(editMessage.Item2, this.PageBoardContext.PageTopic)) { this.Get <LinkBuilder>().AccessDenied(); } } this.editedMessage = editMessage; // we edit message and should transfer both the message ID and TopicID for PageLinks. this.PollList.EditMessageId = this.EditMessageId.Value; } this.HandleUploadControls(); if (!this.IsPostBack) { var normal = new ListItem(this.GetText("normal"), "0"); normal.Attributes.Add( "data-content", $"<span class='select2-image-select-icon'><i class='far fa-comment fa-fw text-secondary me-1'></i>{this.GetText("normal")}</span>"); this.Priority.Items.Add(normal); var sticky = new ListItem(this.GetText("sticky"), "1"); sticky.Attributes.Add( "data-content", $"<span class='select2-image-select-icon'><i class='fas fa-thumbtack fa-fw text-secondary me-1'></i>{this.GetText("sticky")}</span>"); this.Priority.Items.Add(sticky); var announcement = new ListItem(this.GetText("announcement"), "2"); announcement.Attributes.Add( "data-content", $"<span class='select2-image-select-icon'><i class='fas fa-bullhorn fa-fw text-secondary me-1'></i>{this.GetText("announcement")}</span>"); this.Priority.Items.Add(announcement); this.Priority.SelectedIndex = 0; // Allow the Styling of Topic Titles only for Mods or Admins if (this.PageBoardContext.BoardSettings.UseStyledTopicTitles && (this.PageBoardContext.ForumModeratorAccess || this.PageBoardContext.IsAdmin)) { this.StyleRow.Visible = true; } else { this.StyleRow.Visible = false; } this.EditReasonRow.Visible = false; this.PriorityRow.Visible = this.PageBoardContext.ForumPriorityAccess; // update options... this.PostOptions1.Visible = !this.PageBoardContext.IsGuest; this.PostOptions1.PersistentOptionVisible = this.PageBoardContext.IsAdmin || this.PageBoardContext.ForumModeratorAccess; this.PostOptions1.WatchOptionVisible = !this.PageBoardContext.IsGuest; this.PostOptions1.PollOptionVisible = false; if (!this.PageBoardContext.IsGuest) { this.PostOptions1.WatchChecked = this.PageBoardContext.PageTopicID > 0 ? this.GetRepository <WatchTopic>().Check(this.PageBoardContext.PageUserID, this.PageBoardContext.PageTopicID).HasValue : this.PageBoardContext.PageUser.AutoWatchTopics; } if (this.PageBoardContext.IsGuest && this.PageBoardContext.BoardSettings.EnableCaptchaForGuests || this.PageBoardContext.BoardSettings.EnableCaptchaForPost && !this.PageBoardContext.PageUser.UserFlags.IsCaptchaExcluded) { this.imgCaptcha.ImageUrl = CaptchaHelper.GetCaptcha(); this.tr_captcha1.Visible = true; this.tr_captcha2.Visible = true; } this.PageLinks.AddRoot(); this.PageLinks.AddCategory(this.PageBoardContext.PageCategory); this.PageLinks.AddForum(this.PageBoardContext.PageForum); // editing a message... this.InitEditedPost(this.editedMessage); this.PollList.EditMessageId = this.EditMessageId.Value; // form user is only for "Guest" if (this.PageBoardContext.IsGuest) { this.From.Text = this.PageBoardContext.PageUser.DisplayOrUserName(); this.FromRow.Visible = false; } } // Set Poll this.PollId = this.PageBoardContext.PageTopic.PollID; this.PollList.TopicId = this.PageBoardContext.PageTopicID; this.PollList.PollId = this.PollId; }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.PageBoardContext.PageForumID == 0) { this.Get <LinkBuilder>().AccessDenied(); } if (!this.PageBoardContext.ForumPostAccess) { this.Get <LinkBuilder>().AccessDenied(); } this.Title.Text = this.GetText("NEWTOPIC"); this.HandleUploadControls(); if (this.IsPostBack) { return; } var normal = new ListItem(this.GetText("normal"), "0"); normal.Attributes.Add( "data-content", $"<span class='select2-image-select-icon'><i class='far fa-comment fa-fw text-secondary me-1'></i>{this.GetText("normal")}</span>"); this.Priority.Items.Add(normal); var sticky = new ListItem(this.GetText("sticky"), "1"); sticky.Attributes.Add( "data-content", $"<span class='select2-image-select-icon'><i class='fas fa-thumbtack fa-fw text-secondary me-1'></i>{this.GetText("sticky")}</span>"); this.Priority.Items.Add(sticky); var announcement = new ListItem(this.GetText("announcement"), "2"); announcement.Attributes.Add( "data-content", $"<span class='select2-image-select-icon'><i class='fas fa-bullhorn fa-fw text-secondary me-1'></i>{this.GetText("announcement")}</span>"); this.Priority.Items.Add(announcement); this.Priority.SelectedIndex = 0; // Allow the Styling of Topic Titles only for Mods or Admins if (this.PageBoardContext.BoardSettings.UseStyledTopicTitles && (this.PageBoardContext.ForumModeratorAccess || this.PageBoardContext.IsAdmin)) { this.StyleRow.Visible = true; } else { this.StyleRow.Visible = false; } this.PriorityRow.Visible = this.PageBoardContext.ForumPriorityAccess; // update options... this.PostOptions1.Visible = !this.PageBoardContext.IsGuest; this.PostOptions1.PersistentOptionVisible = this.PageBoardContext.IsAdmin || this.PageBoardContext.ForumModeratorAccess; this.PostOptions1.WatchOptionVisible = !this.PageBoardContext.IsGuest; this.PostOptions1.PollOptionVisible = this.PageBoardContext.ForumPollAccess; if (!this.PageBoardContext.IsGuest) { this.PostOptions1.WatchChecked = this.PageBoardContext.PageTopicID > 0 ? this.GetRepository <WatchTopic>().Check(this.PageBoardContext.PageUserID, this.PageBoardContext.PageTopicID).HasValue : this.PageBoardContext.PageUser.AutoWatchTopics; } if (this.PageBoardContext.IsGuest && this.PageBoardContext.BoardSettings.EnableCaptchaForGuests || this.PageBoardContext.BoardSettings.EnableCaptchaForPost && !this.PageBoardContext.PageUser.UserFlags.IsCaptchaExcluded) { this.imgCaptcha.ImageUrl = CaptchaHelper.GetCaptcha(); this.tr_captcha1.Visible = true; this.tr_captcha2.Visible = true; } // enable similar topics search this.TopicSubjectTextBox.CssClass += " searchSimilarTopics"; if (!this.PageBoardContext.IsGuest) { return; } // form user is only for "Guest" this.From.Text = this.PageBoardContext.PageUser.DisplayOrUserName(); if (this.User != null) { this.FromRow.Visible = false; } }