自从公司网站http://bbs.cnfdc.com.cn 用上了cs2.0,就有同事给我提出,能不能添加一个帖子底部的快速回复,这样可以很方便的回复帖子,当时刚接触cs,没有弄,现在,觉得对于cs比较熟悉了,于是就下手做了一个,没想到,成功了,现在就和大家分享一下吧。
我采用的是cs的标准方法,即用户控件的方式,建立一个皮肤文件,然后给这个皮肤文件对应写一个类。皮肤文件可以说是skin-Login.ascx和CreateQuickReplay.ascx的混合体,类文件也一样,不过由于要求游客可以通过一并输入用户名和密码的方式来发帖,所以先登录用户,这里就去掉了一些验证,放在用户登录后进行。
先把初步的皮肤文件的代码放上来,文件名Skin-ThreadQuickReply.ascx,放在default主题目录下
<%
...
@ Control Language="C#"
%>
<% ... @ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>
<% ... @ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<% ... @ Import Namespace="CommunityServer.Discussions.Controls" %>
<% ... @ Import Namespace="CommunityServer.Discussions.Components" %>
<% ... @ Import Namespace="CommunityServer.Components" %>
<% ... @ Import Namespace="CommunityServer.Controls" %>
<% ... @ Import Namespace="CommunityServer" %>
< div class ="CommonContentArea" >
< div class ="CommonContent" >
< div class ="CommonFormArea" >
< ul class ="ForumPostList" >
< li >
< div class ="ForumPostArea" >
< h4 class ="ForumPostHeader" >
< table cellpadding ="0" cellspacing ="0" border ="0" width ="100%" >
< tr valign ="middle" >
< td align ="left" > 快速回复主题 </ td >
< td align ="right" class ="ForumPostHeaderControlArea" >
</ td >
</ tr >
</ table >
</ h4 >
< table cellspacing ="0" cellpadding ="0" border ="0" width ="100%" style ="table-layout: auto;" >
< tr valign =top >
< td rowspan ="2" class ="ForumPostUserArea" >
< div class ="ForumPostUserContent" style ="text-align:left" >
< CSD:UserPermissions runat ="server" id ="Userpermissions1" />
</ div >
</ td >
< td class ="ForumPostContentArea" >
< table width ="100%" cellpadding ="0" cellspacing ="0" border ="0" >
< tr >
< td class ="CommonFormField" colspan ="2" >
< asp:Panel ID ="UserLoginForm" runat ="server" >
< span class ="CommonFormFieldName" >< CS:ResourceLabel ID ="ResourceLabel1" runat ="server" ResourceName ="Login_UserName" /></ span >
< CS:DefaultButtonTextBox Button = "loginButton" id ="username" runat ="server" size ="30" maxlength ="64" />
< span class ="CommonFormFieldName" >< CS:ResourceLabel ID ="ResourceLabel2" runat ="server" ResourceName ="Login_Password" /></ span >
< CS:DefaultButtonTextBox Button = "loginButton" TextMode ="Password" id ="password" runat ="server" size ="11" maxlength ="64" />
< span class ="txt4" > ( < CSD:ForumAnchor AnchorType ="UserForgotPassword" runat ="server" /> ) </ span >
< asp:CheckBox type ="checkbox" Checked ="true" runat ="server" id ="autoLogin" />
< asp:LinkButton id ="loginButton" runat ="server" CssClass = "CommonTextButton" />< a href ="/user/CreateUser.aspx" > 立即注册 </ a >
</ asp:Panel >
</ td >
</ tr >
< tr >
< td class ="CommonFormFieldName" >< CS:ResourceLabel runat ="server" ResourceName ="SendEmail_Subject" id ="rc_send_subject" /></ td >
< td class ="CommonFormField" >< asp:textbox autocomplete ="off" id ="PostSubject" runat ="server" columns ="80" />< asp:requiredfieldvalidator id ="SubjectValidator" runat ="server" Cssclass ="CommonValidationWarning" ControlToValidate ="PostSubject" > * </ asp:requiredfieldvalidator ></ td >
</ tr >
< tr >
< td colspan =2 class ="CommonFormField" >
< asp:requiredfieldvalidator id ="Requiredfieldvalidator1" runat ="server" Cssclass ="CommonValidationWarning" ControlToValidate ="PostBody" > * </ asp:requiredfieldvalidator >
< CS:Editor runat ="Server" EnableHtmlModeEditing ="false" id ="PostBody" Width ="660" Height ="200" />
</ td >
</ tr >
< tr >
< td colspan =2 class ="CommonFormField" >
< asp:button id ="SavePost" Runat ="server" Text = " 发表 " />
</ td >
</ tr >
</ table >
</ td >
</ tr >
< tr valign ="bottom" >
< td class ="ForumPostFooterArea" >
< ul class ="ForumPostStatistics CommonPrintHidden" style ="clear: both;" >
< li ></ li >
</ ul >
</ td >
</ tr >
</ table >
</ div >
</ li >
</ ul >
</ div >
</ div >
</ div >
<% ... @ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>
<% ... @ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<% ... @ Import Namespace="CommunityServer.Discussions.Controls" %>
<% ... @ Import Namespace="CommunityServer.Discussions.Components" %>
<% ... @ Import Namespace="CommunityServer.Components" %>
<% ... @ Import Namespace="CommunityServer.Controls" %>
<% ... @ Import Namespace="CommunityServer" %>
< div class ="CommonContentArea" >
< div class ="CommonContent" >
< div class ="CommonFormArea" >
< ul class ="ForumPostList" >
< li >
< div class ="ForumPostArea" >
< h4 class ="ForumPostHeader" >
< table cellpadding ="0" cellspacing ="0" border ="0" width ="100%" >
< tr valign ="middle" >
< td align ="left" > 快速回复主题 </ td >
< td align ="right" class ="ForumPostHeaderControlArea" >
</ td >
</ tr >
</ table >
</ h4 >
< table cellspacing ="0" cellpadding ="0" border ="0" width ="100%" style ="table-layout: auto;" >
< tr valign =top >
< td rowspan ="2" class ="ForumPostUserArea" >
< div class ="ForumPostUserContent" style ="text-align:left" >
< CSD:UserPermissions runat ="server" id ="Userpermissions1" />
</ div >
</ td >
< td class ="ForumPostContentArea" >
< table width ="100%" cellpadding ="0" cellspacing ="0" border ="0" >
< tr >
< td class ="CommonFormField" colspan ="2" >
< asp:Panel ID ="UserLoginForm" runat ="server" >
< span class ="CommonFormFieldName" >< CS:ResourceLabel ID ="ResourceLabel1" runat ="server" ResourceName ="Login_UserName" /></ span >
< CS:DefaultButtonTextBox Button = "loginButton" id ="username" runat ="server" size ="30" maxlength ="64" />
< span class ="CommonFormFieldName" >< CS:ResourceLabel ID ="ResourceLabel2" runat ="server" ResourceName ="Login_Password" /></ span >
< CS:DefaultButtonTextBox Button = "loginButton" TextMode ="Password" id ="password" runat ="server" size ="11" maxlength ="64" />
< span class ="txt4" > ( < CSD:ForumAnchor AnchorType ="UserForgotPassword" runat ="server" /> ) </ span >
< asp:CheckBox type ="checkbox" Checked ="true" runat ="server" id ="autoLogin" />
< asp:LinkButton id ="loginButton" runat ="server" CssClass = "CommonTextButton" />< a href ="/user/CreateUser.aspx" > 立即注册 </ a >
</ asp:Panel >
</ td >
</ tr >
< tr >
< td class ="CommonFormFieldName" >< CS:ResourceLabel runat ="server" ResourceName ="SendEmail_Subject" id ="rc_send_subject" /></ td >
< td class ="CommonFormField" >< asp:textbox autocomplete ="off" id ="PostSubject" runat ="server" columns ="80" />< asp:requiredfieldvalidator id ="SubjectValidator" runat ="server" Cssclass ="CommonValidationWarning" ControlToValidate ="PostSubject" > * </ asp:requiredfieldvalidator ></ td >
</ tr >
< tr >
< td colspan =2 class ="CommonFormField" >
< asp:requiredfieldvalidator id ="Requiredfieldvalidator1" runat ="server" Cssclass ="CommonValidationWarning" ControlToValidate ="PostBody" > * </ asp:requiredfieldvalidator >
< CS:Editor runat ="Server" EnableHtmlModeEditing ="false" id ="PostBody" Width ="660" Height ="200" />
</ td >
</ tr >
< tr >
< td colspan =2 class ="CommonFormField" >
< asp:button id ="SavePost" Runat ="server" Text = " 发表 " />
</ td >
</ tr >
</ table >
</ td >
</ tr >
< tr valign ="bottom" >
< td class ="ForumPostFooterArea" >
< ul class ="ForumPostStatistics CommonPrintHidden" style ="clear: both;" >
< li ></ li >
</ ul >
</ td >
</ tr >
</ table >
</ div >
</ li >
</ ul >
</ div >
</ div >
</ div >
然后就是ThreadQuickReply.cs,放在CommunityServerForums20项目的根目录下即可:
//
------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
// ------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
using System.Web.Security;
namespace CommunityServer.Discussions.Controls
... {
/**//// <summary>
/// 用来在主题下直接快速回复
/// 作者:王勇
/// 日期:2006-8-14
/// email:wangyong.yichang@gmail.com
/// qq:12586093
/// </summary>
public class ThreadQuickReply : CommunityServer.Controls.TemplatedWebControl
...{
public ThreadQuickReply()
...{
Initialize();
}
private void Initialize()
...{
//CSEvents.AuthorizePost();
if (context.PostID > 0)
...{
postReplyingTo = Posts.GetPost(context.PostID, context.User.UserID);
forum = postReplyingTo.Section as Forum;
}
if (postReplyingTo == null)
...{
throw new CSException(CSExceptionType.PostNotFound);
}
// Security check to see if the forum allows anonymous posts
//
//if (context.User.IsAnonymous && (!forum.EnableAnonymousPosting || !context.SiteSettings.EnableAnonymousUserPosting))
//{
// if (!Context.Request.IsAuthenticated)
// {
// Context.Response.Redirect(Globals.GetSiteUrls().Login);
// Context.Response.End();
// }
//}
if (postReplyingTo.IsLocked)
...{
Context.Response.Redirect(Globals.GetSiteUrls().Post(context.PostID));
Context.Response.End();
}
}
private Editor postBody;
private TextBox postSubject;
private IButton button;
CSContext context = CSContext.Current;
ForumPost postReplyingTo = null;
Forum forum = null;
//提前登录控件
TextBox username;
TextBox password;
IButton loginButton;
CheckBox autoLogin;
// *********************************************************************
// CreateChildControls
//
/**//// <summary>
/// This event handler adds the children controls.
/// </summary>
// ***********************************************************************/
protected override void CreateChildControls()
...{
//If the user is already authenticated we have no work to do
if (Page.Request.IsAuthenticated)
...{
// If the URL is for the login page and the user is already logged in
// we need to throw an access denied exception
//if (Globals.GetSiteUrls().Login.StartsWith(context.Context.Request.Path))
// throw new CSException(CSExceptionType.UserAlreadyLoggedIn, context.ReturnUrl);
//return;
}
base.CreateChildControls();
}
protected override void AttachChildControls()
...{
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
postBody = FindControl("PostBody") as Editor;
postSubject = FindControl("PostSubject") as TextBox;
button = FindButton("SavePost");
if (button != null)
button.Click += new EventHandler(button_Click);
string replyPrePend = ResourceManager.GetString("CreateEditPost_ReplyPrePend");
if (postReplyingTo.Subject.StartsWith(replyPrePend))
...{
postSubject.Text = Globals.HtmlDecode(postReplyingTo.Subject);
}
else
...{
postSubject.Text = replyPrePend + Globals.HtmlDecode(postReplyingTo.Subject);
}
//Head.AddTitle(Formatter.RemoveHtml("快速回复: " + postReplyingTo.Subject, 60), Context);
//登录部分
// Find the username control
username = (TextBox)FindControl("username");
// Find the password control
password = (TextBox)FindControl("password");
// Find the login button
loginButton = ButtonManager.Create(FindControl("loginButton"));
//loginButton.Click += new EventHandler(LoginButton_Click);
loginButton.Text = ResourceManager.GetString("LoginSmall_Button");
//取消登录按钮
loginButton.Visible = false;
//若登录了,则隐藏控件
Panel UserLoginForm = FindControl("UserLoginForm") as Panel;
if (context.User.Username.ToLower() != "anonymous")
...{
UserLoginForm.Visible = false;
}
// Find the autologin checkbox
autoLogin = (CheckBox)FindControl("autoLogin");
autoLogin.Text = ResourceManager.GetString("LoginSmall_AutoLogin");
//autoLogin.AutoPostBack = true;
//autoLogin.CheckedChanged += new EventHandler( AutoLogin_OnCheckedChanged );
// Restore autologin status from the auto login cookie
AutoLoginCookie alCookie = new AutoLoginCookie();
autoLogin.Checked = alCookie.GetValue();
//username.Focus();
}
/**//// <summary>
/// Event handler to update auto login cookie value.
/// </summary>
protected void AutoLogin_OnCheckedChanged(Object sender, EventArgs e)
...{
AutoLoginCookie alCookie = new AutoLoginCookie();
alCookie.Write(autoLogin.Checked);
}
// *********************************************************************
// LoginButton_Click
//
/**//// <summary>
/// Event handler to handle the login button click event
/// </summary>
// ***********************************************************************/
public void LoginButton_Click()
...{
User userToLogin = new User();
//string redirectUrl = null;
// Save in cookie auto login user's preference
// only if it wasn't previously set or the cookie value differs from
// login's autologin checkbox status.
//
AutoLoginCookie alCookie = new AutoLoginCookie();
if (!alCookie.HasValue ||
(alCookie.HasValue && (alCookie.GetValue() != autoLogin.Checked)))
...{
alCookie.Write(autoLogin.Checked);
}
if (!Page.IsValid)
return;
userToLogin.Username = username.Text;
userToLogin.Password = password.Text;
LoginUserStatus loginStatus = Users.ValidUser(userToLogin);
bool enableBannedUsersToLogin = CSContext.Current.SiteSettings.EnableBannedUsersToLogin;
// Change to let banned users in
//
if (loginStatus == LoginUserStatus.Success ||
(enableBannedUsersToLogin && loginStatus == LoginUserStatus.AccountBanned))
...{
// Are we allowing login?
// TODO -- this could be better optimized
if (!CSContext.Current.SiteSettings.AllowLogin && !userToLogin.IsAdministrator)
...{
throw new CSException(CSExceptionType.UserLoginDisabled);
}
HttpCookie formsAuthCookie;
formsAuthCookie = FormsAuthentication.GetAuthCookie(userToLogin.Username, autoLogin.Checked);
UserCookie userCookie = context.User.GetUserCookie();
userCookie.WriteCookie(formsAuthCookie, 30, autoLogin.Checked);
// Get the link from the context
//if ((CSContext.Current.ReturnUrl != null) && (CSContext.Current.ReturnUrl.Trim() != string.Empty))
// redirectUrl = CSContext.Current.ReturnUrl;
// If none, get the stored redirect url
//if ((redirectUrl == null) && (ReferralLink != null) && (ReferralLink.Trim() != string.Empty))
// redirectUrl = ReferralLink;
// Check to ensure we aren't redirecting back to a Message prompt or back to the logout screen
// Or ChangePassword*, or CreateUser*, or EmailForgottenPassword*
// Or, if no URL, use appPath
//if (Globals.IsNullorEmpty(redirectUrl)
// || (redirectUrl.IndexOf("MessageID") != -1)
// || (redirectUrl.IndexOf(Globals.GetSiteUrls().Logout) != -1)
// || (redirectUrl.IndexOf("ChangePassword") != -1)
// || (redirectUrl.IndexOf("EmailForgottenPassword") != -1))
// redirectUrl = Globals.GetSiteUrls().Home;
//LeaveSecureConnection(redirectUrl);
}
else if (loginStatus == LoginUserStatus.InvalidCredentials)
...{
// Invalid Credentials
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserInvalidCredentials), true);
}
else if (loginStatus == LoginUserStatus.AccountPending)
...{
// Account not approved yet
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserAccountPending), true);
}
else if (loginStatus == LoginUserStatus.AccountDisapproved)
...{
// Account disapproved
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserAccountDisapproved), true);
}
else if (loginStatus == LoginUserStatus.UnknownError)
...{
// Unknown error because of miss-syncronization of internal data
throw new CSException(CSExceptionType.UserUnknownLoginError);
}
// Reject banned users if they are not allowed to
// pass through login.
//
else if (!enableBannedUsersToLogin && loginStatus == LoginUserStatus.AccountBanned)
...{
// Account banned
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserAccountBanned), true);
}
}
private void button_Click(object sender, EventArgs e)
...{
//登录用户
if (context.User.Username.ToLower() == "anonymous")
...{
LoginButton_Click();
}
Permissions.AccessCheck(forum, Permission.Reply, context.User, postReplyingTo);
// Only proceed if the post is valid
//
if (!Page.IsValid)
return;
Thread postToAdd = new Thread();
if (postReplyingTo.PostID != postReplyingTo.ParentID)
...{
postToAdd.ParentID = postReplyingTo.ParentID;
}
postToAdd.PostLevel = postReplyingTo.PostLevel;
postToAdd.SectionID = postReplyingTo.SectionID;
// Get initial post's posting date
postToAdd.PostDate = postReplyingTo.PostDate;
// Get the current StickyDate
Thread thread = Threads.GetThread(postReplyingTo.ThreadID);
postToAdd.IsSticky = thread.IsSticky;
postToAdd.StickyDate = thread.StickyDate;
postToAdd.Username = context.User.Username;
postToAdd.Subject = postSubject.Text;
postToAdd.IsLocked = false;
postToAdd.IsTracked = true;
postToAdd.User = context.User;
postToAdd.IsAnonymousPost = false;
postToAdd.IsIgnoredPost = context.User.IsIgnored;
postToAdd.PostType = PostContentType.HTML;
postToAdd.Body = postBody.Text;
postToAdd.ParentID = context.PostID;
ForumPost fp=Posts.AddPost(postToAdd, context.User);
//HttpCookie cookie = Context.Request.Cookies["CSQuickReplyCheck"];
bool isChecked = false;
isChecked = true;
HttpCookie cookie = new HttpCookie("CSQuickReplyCheck", isChecked.ToString());
cookie.Expires = DateTime.Now.AddDays(99);
Context.Response.Cookies.Add(cookie);
//string returnValue = isChecked ? "true" : "false";
//Modal.ClosePage(this.Page, returnValue);
HttpContext.Current.Response.Redirect("/forums/permalink/" + fp.ParentID + "/" + fp.PostID + "/ShowThread.aspx#" + fp.PostID);
}
}
}
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
// ------------------------------------------------------------------------------
using System;
using System.Web;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
using System.Web.Security;
namespace CommunityServer.Discussions.Controls
... {
/**//// <summary>
/// 用来在主题下直接快速回复
/// 作者:王勇
/// 日期:2006-8-14
/// email:wangyong.yichang@gmail.com
/// qq:12586093
/// </summary>
public class ThreadQuickReply : CommunityServer.Controls.TemplatedWebControl
...{
public ThreadQuickReply()
...{
Initialize();
}
private void Initialize()
...{
//CSEvents.AuthorizePost();
if (context.PostID > 0)
...{
postReplyingTo = Posts.GetPost(context.PostID, context.User.UserID);
forum = postReplyingTo.Section as Forum;
}
if (postReplyingTo == null)
...{
throw new CSException(CSExceptionType.PostNotFound);
}
// Security check to see if the forum allows anonymous posts
//
//if (context.User.IsAnonymous && (!forum.EnableAnonymousPosting || !context.SiteSettings.EnableAnonymousUserPosting))
//{
// if (!Context.Request.IsAuthenticated)
// {
// Context.Response.Redirect(Globals.GetSiteUrls().Login);
// Context.Response.End();
// }
//}
if (postReplyingTo.IsLocked)
...{
Context.Response.Redirect(Globals.GetSiteUrls().Post(context.PostID));
Context.Response.End();
}
}
private Editor postBody;
private TextBox postSubject;
private IButton button;
CSContext context = CSContext.Current;
ForumPost postReplyingTo = null;
Forum forum = null;
//提前登录控件
TextBox username;
TextBox password;
IButton loginButton;
CheckBox autoLogin;
// *********************************************************************
// CreateChildControls
//
/**//// <summary>
/// This event handler adds the children controls.
/// </summary>
// ***********************************************************************/
protected override void CreateChildControls()
...{
//If the user is already authenticated we have no work to do
if (Page.Request.IsAuthenticated)
...{
// If the URL is for the login page and the user is already logged in
// we need to throw an access denied exception
//if (Globals.GetSiteUrls().Login.StartsWith(context.Context.Request.Path))
// throw new CSException(CSExceptionType.UserAlreadyLoggedIn, context.ReturnUrl);
//return;
}
base.CreateChildControls();
}
protected override void AttachChildControls()
...{
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
postBody = FindControl("PostBody") as Editor;
postSubject = FindControl("PostSubject") as TextBox;
button = FindButton("SavePost");
if (button != null)
button.Click += new EventHandler(button_Click);
string replyPrePend = ResourceManager.GetString("CreateEditPost_ReplyPrePend");
if (postReplyingTo.Subject.StartsWith(replyPrePend))
...{
postSubject.Text = Globals.HtmlDecode(postReplyingTo.Subject);
}
else
...{
postSubject.Text = replyPrePend + Globals.HtmlDecode(postReplyingTo.Subject);
}
//Head.AddTitle(Formatter.RemoveHtml("快速回复: " + postReplyingTo.Subject, 60), Context);
//登录部分
// Find the username control
username = (TextBox)FindControl("username");
// Find the password control
password = (TextBox)FindControl("password");
// Find the login button
loginButton = ButtonManager.Create(FindControl("loginButton"));
//loginButton.Click += new EventHandler(LoginButton_Click);
loginButton.Text = ResourceManager.GetString("LoginSmall_Button");
//取消登录按钮
loginButton.Visible = false;
//若登录了,则隐藏控件
Panel UserLoginForm = FindControl("UserLoginForm") as Panel;
if (context.User.Username.ToLower() != "anonymous")
...{
UserLoginForm.Visible = false;
}
// Find the autologin checkbox
autoLogin = (CheckBox)FindControl("autoLogin");
autoLogin.Text = ResourceManager.GetString("LoginSmall_AutoLogin");
//autoLogin.AutoPostBack = true;
//autoLogin.CheckedChanged += new EventHandler( AutoLogin_OnCheckedChanged );
// Restore autologin status from the auto login cookie
AutoLoginCookie alCookie = new AutoLoginCookie();
autoLogin.Checked = alCookie.GetValue();
//username.Focus();
}
/**//// <summary>
/// Event handler to update auto login cookie value.
/// </summary>
protected void AutoLogin_OnCheckedChanged(Object sender, EventArgs e)
...{
AutoLoginCookie alCookie = new AutoLoginCookie();
alCookie.Write(autoLogin.Checked);
}
// *********************************************************************
// LoginButton_Click
//
/**//// <summary>
/// Event handler to handle the login button click event
/// </summary>
// ***********************************************************************/
public void LoginButton_Click()
...{
User userToLogin = new User();
//string redirectUrl = null;
// Save in cookie auto login user's preference
// only if it wasn't previously set or the cookie value differs from
// login's autologin checkbox status.
//
AutoLoginCookie alCookie = new AutoLoginCookie();
if (!alCookie.HasValue ||
(alCookie.HasValue && (alCookie.GetValue() != autoLogin.Checked)))
...{
alCookie.Write(autoLogin.Checked);
}
if (!Page.IsValid)
return;
userToLogin.Username = username.Text;
userToLogin.Password = password.Text;
LoginUserStatus loginStatus = Users.ValidUser(userToLogin);
bool enableBannedUsersToLogin = CSContext.Current.SiteSettings.EnableBannedUsersToLogin;
// Change to let banned users in
//
if (loginStatus == LoginUserStatus.Success ||
(enableBannedUsersToLogin && loginStatus == LoginUserStatus.AccountBanned))
...{
// Are we allowing login?
// TODO -- this could be better optimized
if (!CSContext.Current.SiteSettings.AllowLogin && !userToLogin.IsAdministrator)
...{
throw new CSException(CSExceptionType.UserLoginDisabled);
}
HttpCookie formsAuthCookie;
formsAuthCookie = FormsAuthentication.GetAuthCookie(userToLogin.Username, autoLogin.Checked);
UserCookie userCookie = context.User.GetUserCookie();
userCookie.WriteCookie(formsAuthCookie, 30, autoLogin.Checked);
// Get the link from the context
//if ((CSContext.Current.ReturnUrl != null) && (CSContext.Current.ReturnUrl.Trim() != string.Empty))
// redirectUrl = CSContext.Current.ReturnUrl;
// If none, get the stored redirect url
//if ((redirectUrl == null) && (ReferralLink != null) && (ReferralLink.Trim() != string.Empty))
// redirectUrl = ReferralLink;
// Check to ensure we aren't redirecting back to a Message prompt or back to the logout screen
// Or ChangePassword*, or CreateUser*, or EmailForgottenPassword*
// Or, if no URL, use appPath
//if (Globals.IsNullorEmpty(redirectUrl)
// || (redirectUrl.IndexOf("MessageID") != -1)
// || (redirectUrl.IndexOf(Globals.GetSiteUrls().Logout) != -1)
// || (redirectUrl.IndexOf("ChangePassword") != -1)
// || (redirectUrl.IndexOf("EmailForgottenPassword") != -1))
// redirectUrl = Globals.GetSiteUrls().Home;
//LeaveSecureConnection(redirectUrl);
}
else if (loginStatus == LoginUserStatus.InvalidCredentials)
...{
// Invalid Credentials
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserInvalidCredentials), true);
}
else if (loginStatus == LoginUserStatus.AccountPending)
...{
// Account not approved yet
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserAccountPending), true);
}
else if (loginStatus == LoginUserStatus.AccountDisapproved)
...{
// Account disapproved
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserAccountDisapproved), true);
}
else if (loginStatus == LoginUserStatus.UnknownError)
...{
// Unknown error because of miss-syncronization of internal data
throw new CSException(CSExceptionType.UserUnknownLoginError);
}
// Reject banned users if they are not allowed to
// pass through login.
//
else if (!enableBannedUsersToLogin && loginStatus == LoginUserStatus.AccountBanned)
...{
// Account banned
Page.Response.Redirect(Globals.GetSiteUrls().Message(CSExceptionType.UserAccountBanned), true);
}
}
private void button_Click(object sender, EventArgs e)
...{
//登录用户
if (context.User.Username.ToLower() == "anonymous")
...{
LoginButton_Click();
}
Permissions.AccessCheck(forum, Permission.Reply, context.User, postReplyingTo);
// Only proceed if the post is valid
//
if (!Page.IsValid)
return;
Thread postToAdd = new Thread();
if (postReplyingTo.PostID != postReplyingTo.ParentID)
...{
postToAdd.ParentID = postReplyingTo.ParentID;
}
postToAdd.PostLevel = postReplyingTo.PostLevel;
postToAdd.SectionID = postReplyingTo.SectionID;
// Get initial post's posting date
postToAdd.PostDate = postReplyingTo.PostDate;
// Get the current StickyDate
Thread thread = Threads.GetThread(postReplyingTo.ThreadID);
postToAdd.IsSticky = thread.IsSticky;
postToAdd.StickyDate = thread.StickyDate;
postToAdd.Username = context.User.Username;
postToAdd.Subject = postSubject.Text;
postToAdd.IsLocked = false;
postToAdd.IsTracked = true;
postToAdd.User = context.User;
postToAdd.IsAnonymousPost = false;
postToAdd.IsIgnoredPost = context.User.IsIgnored;
postToAdd.PostType = PostContentType.HTML;
postToAdd.Body = postBody.Text;
postToAdd.ParentID = context.PostID;
ForumPost fp=Posts.AddPost(postToAdd, context.User);
//HttpCookie cookie = Context.Request.Cookies["CSQuickReplyCheck"];
bool isChecked = false;
isChecked = true;
HttpCookie cookie = new HttpCookie("CSQuickReplyCheck", isChecked.ToString());
cookie.Expires = DateTime.Now.AddDays(99);
Context.Response.Cookies.Add(cookie);
//string returnValue = isChecked ? "true" : "false";
//Modal.ClosePage(this.Page, returnValue);
HttpContext.Current.Response.Redirect("/forums/permalink/" + fp.ParentID + "/" + fp.PostID + "/ShowThread.aspx#" + fp.PostID);
}
}
}
然后重新编译这个项目,将生成的dll类库拷贝到cs的bin目录,然后在模板View-PostFlatView.ascx的最末尾加入
<
CSD:ThreadQuickReply
runat
="server"
ID
="ThreadQuickReply1"
/>
没有什么问题的话,应该就可以运行了。有什么问题,我们一起交流吧!