| namespace Discuz.ForumPage { public partial class AutoWebsite : BasePage { private string SESSION_KEY_ACCOUNT ; private readonly string PUBLIC_KEY = "@CN80s_passport_2007"; private const string C; private int uid = -1; private int pagevistcount = 0; private string bbsUrl = ConfigurationManager.AppSettings["BBSURL"]; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (HttpContext.Current.Session["IAMLOGIN"] != null) { SESSION_KEY_ACCOUNT = HttpContext.Current.Session["IAMLOGIN"].ToString(); if (Session["vistcount"] != null) pagevistcount = Convert.ToInt32(Session["vistcount"]); } OnPageInit(); } } private void OnPageInit() { pagevistcount++; Session["vistcount"] = pagevistcount.ToString(); if (pagevistcount > 2) { Session.Remove("vistcount"); HttpContext.Current.Response.Redirect(bbsUrl); } if (HttpContext.Current.Request.QueryString["l"] != null && HttpContext.Current.Session["IAMLOGIN"] != null) { Session.Remove("vistcount"); string acc = HttpContext.Current.Request.QueryString["l"].Trim(); acc = HttpUtility.UrlDecode(acc); acc = acc.Replace(" ", "+"); string key = SESSION_KEY_ACCOUNT; HttpContext.Current.Session.Remove("IAMLOGIN"); acc = Crypto.Decrypt(acc, key + PUBLIC_KEY); string[] np = acc.Split('|'); //已有网站其它版块用户信息来访问 if (!Users.Exists(np[0])) { //论坛不存在此用户名,则自动注册此用户名 if (AutoRegisterBbs(np[0], CONSTPASSWORD, np[2]) != -1) { HttpContext.Current.Response.Redirect(bbsUrl); } } else { //论坛存在此用户,则自动登陆论坛 uid = Users.GetUserID(np[0]);//根据用户名得到它的uid if (uid != -1) { AutoLoginBbs(np[0], CONSTPASSWORD); } else { HttpContext.Current.Response.Redirect(bbsUrl); } } } else { //转向登陆界面 string url = ConfigurationManager.AppSettings["PassportURL"]; string backUrl = HttpUtility.UrlEncode(HttpContext.Current.Request.Url.ToString()); string ec = Guid.NewGuid().ToString(); HttpContext.Current.Session.Add("IAMLOGIN", ec); HttpContext.Current.Response.Redirect(url + "?t=0&backUrl=" + backUrl + "&ec=" + ec); } } /// <summary> /// 自动登陆论坛 /// </summary> private void AutoLoginBbs(string userName, string userPwd) { ShortUserInfo userinfo = Users.GetShortUserInfo(uid); LoginLogs.DeleteLoginLog(DNTRequest.GetIP()); UserCredits.UpdateUserCredits(uid); ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey, 0, 1); OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0, config.Onlinetimeout); Users.UpdateUserLastvisit(uid, DNTRequest.GetIP()); this.username = userName; this.userid = uid; //取得当前用户的用户组信息 this.usergroupinfo = UserGroups.GetUserGroupInfo(userinfo.Groupid); // 根据用户组得到相关联的管理组id this.useradminid = usergroupinfo.Radminid; //根据论坛积分公式更新用户积分 UserCredits.UpdateUserCredits(uid); //将当前用户的登陆信息写入COOKIE ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey); //更新用户的当前动作及相关信息 OnlineUsers.UpdateAction(olid, UserAction.Register.ActionID, 0, config.Onlinetimeout); //重计统计缓存 Statistics.ReSetStatisticsCache(); SetUrl("index.aspx"); SetMetaRefresh(); SetShowBackLink(false); AddMsgLine("登录成功, 返回首页"); HttpContext.Current.Response.Redirect(bbsUrl); } /// <summary> /// 自动注册论坛帐号 /// </summary> private int AutoRegisterBbs(string userName,string userPwd,string email) { UserInfo userinfo = new UserInfo(); userinfo.Username = userName; userinfo.Nickname = userName; userinfo.Password = Utils.MD5(userPwd); userinfo.Email = email; userinfo.Accessmasks = 0; userinfo.Adminid = 0; userinfo.Authflag = 0; userinfo.Authstr = ""; userinfo.Authtime = ""; userinfo.Avatar = @"avatars\common\0.gif"; userinfo.Avatarheight = 0; userinfo.Avatarshowid = 0; userinfo.Avatarwidth = 0; userinfo.Bday = ""; userinfo.Bio = ""; userinfo.Credits = 10; userinfo.Customstatus = ""; userinfo.Digestposts = 0; userinfo.Extcredits1 = 0f; userinfo.Extcredits2 = 0f; userinfo.Extcredits3 = 0f; userinfo.Extcredits4 = 0f; userinfo.Extcredits5 = 0f; userinfo.Extcredits6 = 0f; userinfo.Extcredits7 = 0f; userinfo.Extcredits8 = 0f; userinfo.Extgroupids = ""; userinfo.Gender = 0; userinfo.Groupexpiry = 0; userinfo.Groupid = UserCredits.GetCreditsUserGroupID(0).Groupid; userinfo.Icq = ""; userinfo.Idcard = ""; userinfo.Invisible = 0; userinfo.Joindate = Utils.GetDateTime(); userinfo.Lastactivity = Utils.GetDateTime(); userinfo.Lastip = DNTRequest.GetIP(); userinfo.Lastpost = Utils.GetDateTime(); userinfo.Lastpostid = 0; userinfo.Lastposttitle = ""; userinfo.Lastvisit = Utils.GetDateTime(); userinfo.Location = ""; userinfo.Medals = ""; userinfo.Mobile = ""; userinfo.Msn = ""; userinfo.Newpm = 0; userinfo.Newpmcount = 0; userinfo.Newsletter = ReceivePMSettingType.ReceiveAllPMWithHint; userinfo.Oltime = 0; userinfo.Onlinestate = 1; userinfo.Pageviews = 0; userinfo.Phone = ""; userinfo.Pmsound = 0; userinfo.Posts = 0; userinfo.Ppp = 0; userinfo.Qq = ""; userinfo.Realname = ""; userinfo.Regip = DNTRequest.GetIP(); userinfo.Secques = ""; userinfo.Showemail = 1; userinfo.Sightml = ""; userinfo.Signature = ""; userinfo.Sigstatus = 0; userinfo.Skype = ""; userinfo.Spaceid = 0; userinfo.Templateid = 0; userinfo.Tpp = 0; userinfo.Website = ""; userinfo.Yahoo = ""; //创建新用户 int uid = Users.CreateUser(userinfo); if (config.Welcomemsg == 1) { PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo(); string curdatetime = Utils.GetDateTime(); // 收件箱 privatemessageinfo.Message = config.Welcomemsgtxt; privatemessageinfo.Subject = "欢迎您的加入! (请勿回复本信息)"; privatemessageinfo.Msgto = userinfo.Username; privatemessageinfo.Msgtoid = uid; privatemessageinfo.Msgfrom = PrivateMessages.SystemUserName; privatemessageinfo.Msgfromid = 0; privatemessageinfo.New = 1; privatemessageinfo.Postdatetime = curdatetime; privatemessageinfo.Folder = 0; PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0); } if (config.Regverify == 0) { UserCredits.UpdateUserCredits(uid); ForumUtils.WriteUserCookie(uid, -1, config.Passwordkey); OnlineUsers.UpdateAction(olid, UserAction.Register.ActionID, 0, config.Onlinetimeout); Statistics.ReSetStatisticsCache(); SetUrl("index.aspx"); SetMetaRefresh(); SetShowBackLink(false); AddMsgLine("注册成功, 返回登录页"); } return uid; } } } |

| //[behind code] using System; using System.Data; using Discuz.Common; using Discuz.Forum; using Discuz.Web.UI.Pages; using Discuz.Entity; using Discuz.Config; using Discuz.Common.Generic; namespace Discuz.ForumPage { public partial class mytopicsForCN80s : BasePage { /// <summary> /// 主题列表(以List形式存在) /// </summary> public List<MyTopicInfo> topics; /// <summary> /// 主题列表(以DataTable形式存在) /// </summary> public DataTable dtTopics; /// <summary> /// 当前页码 /// </summary> public int pageid; /// <summary> /// 总页数 /// </summary> public int pagecount; /// <summary> /// 主题总数 /// </summary> public int topiccount; /// <summary> /// 分页页码链接 /// </summary> public string pagenumbers; /// <summary> /// 当前登录的用户信息 /// </summary> public UserInfo user = new UserInfo(); /// <summary> /// 默认显示的主题数 /// </summary> private int pagesize = 15; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //this.lb.Text = DateTime.Now.ToString("yyyy年MM月dd日"); SetDataBinder(); } } /// <summary> /// 数据绑定 /// </summary> protected void SetDataBinder() { this.userid = 1;//此处用于页面测试用 user = Users.GetUserInfo(userid); //得到当前用户请求的页数 pageid = DNTRequest.GetInt("page", 1); //获取主题总数 if (userid != -1) { topiccount = Topics.GetTopicsCountbyUserId(this.userid); } else { topiccount = Topics.GetAllTopicCount(0); } //获取总页数 pagecount = topiccount % pagesize == 0 ? topiccount / pagesize : topiccount / pagesize + 1; if (pagecount == 0) { pagecount = 1; } //修正请求页数中可能的错误 if (pageid < 1) { pageid = 1; } if (pageid > pagecount) { pageid = pagecount; } if (userid != -1) { this.topics = Topics.GetTopicsByUserId(this.userid, pageid, pagesize, 600, config.Hottopic); pagenumbers = Utils.GetPageNumbers(pageid, pagecount, "mytopicsForCN80s.aspx", 10); lt01.Text = GetDataHtml(topics); } else { this.dtTopics = Focuses.GetTopicList(1000, -1, 0,TopicTimeType.All,TopicOrderType.LastPost, false, 1, false); pagenumbers = Utils.GetPageNumbers(pageid, pagecount, "mytopicsForCN80s.aspx", 10); lt01.Text = GetDataHtml(dtTopics); } } private string GetDataHtml(object obj) { string html = ""; html += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"tabTopicList\">\r\n"; html += "<thead>\r\n"; html += "<tr>\r\n"; html += "<th style=\"width:20%;text-align:left;\">所属版块</th>\r\n"; html += "<th style=\"width:60%;text-align:left;\">帖子标题</th>\r\n"; html += "<th style=\"text-align:left;\">发帖时间</th>\r\n"; html += "</tr>\r\n"; html += "</thead>\r\n"; html += "<tbody>\r\n"; if (obj.GetType() == typeof(List<MyTopicInfo>)) { foreach (MyTopicInfo topic in (List<MyTopicInfo>)obj) { aspxrewriteurl = this.ShowForumAspxRewrite(topic.Fid, 0); html += "<tr>\r\n"; html += "<td style=\"width:20%;\"><a href=\"" + aspxrewriteurl.ToString() + "\">[" + topic.Forumname.ToString().Trim() + "]</a></td>\r\n"; html += "<td style=\"width:50%;\"><a href=\"showtopic.aspx?topicid=" + topic.Tid.ToString().Trim() + "\" target=\"_blank\" title=\"" + topic.Title.ToString().Trim() + "\">" + Utils.GetSubString(topic.Title.ToString().Trim(), 20, "…") + "</a></td>\r\n"; html += "<td>" + Convert.ToDateTime(topic.Postdatetime).ToString("yyyy年MM月dd日") + "</td>\r\n"; html += "</tr>\r\n"; } } else if (obj.GetType() == typeof(DataTable)) { foreach (DataRow dr in ((DataTable)obj).Rows) { aspxrewriteurl = this.ShowForumAspxRewrite(dr["fid"].ToString(), 0); ForumInfo forum = Forums.GetForumInfo(Convert.ToInt32(dr["fid"])); html += "<tr>\r\n"; html += "<td style=\"width:20%;\"><a href=\"" + aspxrewriteurl.ToString() + "\">[" + forum.Name + "]</a></td>\r\n"; html += "<td style=\"width:50%;\"><a href=\"showtopic.aspx?topicid=" + dr["tid"].ToString().Trim() + "\" target=\"_blank\" title=\"" + dr["title"].ToString().Trim() + "\">" + Utils.GetSubString(dr["title"].ToString().Trim(), 20, "…") + "</a></td>\r\n"; html += "<td>" + Convert.ToDateTime(dr["postdatetime"]).ToString("yyyy年MM月dd日") + "</td>\r\n"; html += "</tr>\r\n"; } } html += "</tbody>\r\n"; html += "</table>\r\n"; html += "<div class=\"forumpages\">\r\n"; html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\r\n"; html += "<tr>\r\n"; html += "<td class=\"forumallpages\" width=\"30\">" + pageid.ToString() + "/" + pagecount.ToString() + "页</td>\r\n"; html += "<td width=\"10\"> </td>\r\n"; html += "<td class=\"forumallpages\" style=\"text-align:left;\">" + pagenumbers.ToString() + "</td>\r\n"; html += "</tr>\r\n"; html += "</table>\r\n"; html += "</div>\r\n"; return html; } } } //[page Html Code] <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="mytopicsForCN80s.aspx.cs" Inherits="Discuz.ForumPage.mytopicsForCN80s" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> #form1 *{font-size:13px;} .tabTopicList tr{height:22px;line-height:22px;} .forumpages{ clear: both; margin: 8px auto; height: 22px;width:50%;} .forumpages table{width:90%;} .forumallpages{ border: 1px solid #BDDAF7; background:#F5FAFE ; text-align: center; color: #188BCC; line-height: 22px; padding: 0 4px; } .forumallpages a{ color: #333; padding: 5px 10px; } .forumallpages a:hover{ color: #fff; background: #45ACE1 ; text-decoration:none;} .forumpages span { color:#FFF; padding: 5px 10px; margin: 0 3px; background: #45ACE1 ; } </style> </head> <body> <form id="form1" runat="server" enableviewstate="false"> <div> <asp:Literal ID="lt01" runat="server"></asp:Literal> </div> </form> </body> </html> |
| //[Behind Code] using System; using System.Data; using Discuz.Common; using Discuz.Forum; using Discuz.Web.UI.Pages; using Discuz.Entity; using Discuz.Config; using Discuz.Common.Generic; namespace Discuz.ForumPage { public partial class myDigstTopicForCN80s : BasePage { /// <summary> /// 搜索缓存Id /// </summary> private int searchid; /// <summary> /// 搜索出的主题列表 /// </summary> private DataTable topiclist; /// <summary> /// 主题数量 /// </summary> private int topiccount; /// <summary> /// 当前页码 /// </summary> private int pageid; /// <summary> /// 分页数量 /// </summary> private int pagecount; /// <summary> /// 分页页码链接 /// </summary> private string pagenumbers; /// <summary> /// 每页显示的主题数目 /// </summary> private int pageSize = 15; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SetDataBinder(); } } /// <summary> /// 数据绑定 /// </summary> protected void SetDataBinder() { if (userid != -1) { pageid = DNTRequest.GetInt("page", 1); searchid = Searches.Search(0, userid, usergroupid, "", userid, "digest", "", 0, 0, 0, 0, 0); this.topiclist = Searches.GetSearchCacheList(0, searchid, pageSize, pageid, out topiccount, ""); if (topiccount == 0) { Response.Write("当前没有符合类型的主题……"); Response.End(); } else { CalculateCurrentPage(); //得到页码链接 pagenumbers = Utils.GetPageNumbers(pageid, pagecount, "myDigstTopicForCN80s.aspx?type=''&searchid=" + searchid.ToString(), 8); lt01.Text = GetDataHtml(); } } else { Response.Write("尚未登陆!请登陆后再查询"); Response.End(); } } private string GetDataHtml() { string html = ""; html += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"tabTopicList\">\r\n"; html += "<thead>\r\n"; html += "<tr>\r\n"; html += "<th style=\"width:20%;text-align:left;\">所属版块</th>\r\n"; html += "<th style=\"width:60%;text-align:left;\">帖子标题</th>\r\n"; html += "<th style=\"text-align:left;\">发帖时间</th>\r\n"; html += "</tr>\r\n"; html += "</thead>\r\n"; html += "<tbody>\r\n"; foreach (DataRow dr in topiclist.Rows) { aspxrewriteurl = this.ShowForumAspxRewrite(dr["fid"].ToString(), 0); ForumInfo forum = Forums.GetForumInfo(Convert.ToInt32(dr["fid"])); html += "<tr>\r\n"; html += "<td style=\"width:20%;\"><a href=\"" + aspxrewriteurl.ToString() + "\">[" + forum.Name + "]</a></td>\r\n"; html += "<td style=\"width:50%;\"><a href=\"showtopic.aspx?topicid=" + dr["tid"].ToString().Trim() + "\" target=\"_blank\" title=\"" + dr["title"].ToString().Trim() + "\">" + Utils.GetSubString(dr["title"].ToString().Trim(), 20, "…") + "</a></td>\r\n"; html += "<td>" + Convert.ToDateTime(dr["postdatetime"]).ToString("yyyy年MM月dd日") + "</td>\r\n"; html += "</tr>\r\n"; } html += "</tbody>\r\n"; html += "</table>\r\n"; html += "<div class=\"forumpages\">\r\n"; html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\r\n"; html += "<tr>\r\n"; html += "<td class=\"forumallpages\" width=\"30\">" + pageid.ToString() + "/" + pagecount.ToString() + "页</td>\r\n"; html += "<td width=\"10\"> </td>\r\n"; html += "<td class=\"forumallpages\" style=\"text-align:left;\">" + pagenumbers.ToString() + "</td>\r\n"; html += "</tr>\r\n"; html += "</table>\r\n"; html += "</div>\r\n"; return html; } private void CalculateCurrentPage() { //获取总页数 pagecount = topiccount % pageSize == 0 ? topiccount / pageSize : topiccount / pageSize + 1; if (pagecount == 0) { pagecount = 1; } //修正请求页数中可能的错误 if (pageid < 1) { pageid = 1; } if (pageid > pagecount) { pageid = pagecount; } } private int CalculateCurrentPage(int listcount, int pageid, out int pagecount) { //int pagecount; //获取总页数 pagecount = listcount % pageSize == 0 ? listcount / pageSize : listcount / pageSize + 1; if (pagecount == 0) { pagecount = 1; } //修正请求页数中可能的错误 if (pageid < 1) { pageid = 1; } if (pageid > pagecount) { pageid = pagecount; } return pageid; } } } //[page Html Code] <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="myDigstTopicForCN80s.aspx.cs" Inherits="Discuz.ForumPage.myDigstTopicForCN80s" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> #form1 *{font-size:13px;} .tabTopicList tr{height:22px;line-height:22px;} .forumpages{ clear: both; margin: 8px auto; height: 22px;width:50%;} .forumpages table{width:90%;} .forumallpages{ border: 1px solid #BDDAF7; background:#F5FAFE ; text-align: center; color: #188BCC; line-height: 22px; padding: 0 4px; } .forumallpages a{ color: #333; padding: 5px 10px; } .forumallpages a:hover{ color: #fff; background: #45ACE1 ; text-decoration:none;} .forumpages span { color:#FFF; padding: 5px 10px; margin: 0 3px; background: #45ACE1 ; } </style> </head> <body> <form id="form1" runat="server" enableviewstate="false"> <div> <asp:Literal ID="lt01" runat="server"></asp:Literal> </div> </form> </body> </html> |