discuz !NT 3.5 论坛整合 .net 网站用户登录,退出
2023-09-14 09:00:19 时间
using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls.WebParts; using System.Data; using System.Text; using Discuz.Toolkit; using System.Text.RegularExpressions; using System.Security.Cryptography; using System.Xml.Linq; using System.IO; using Discuz.Common; using Discuz.Forum; using Discuz.Config; using Discuz.Entity; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.Cookies["dnt"] != null && Request.Cookies["dnt"].Values["userid"] != null) { //从cookie中获得UserID int uid = Convert.ToInt32(Request.Cookies["dnt"].Values["userid"].ToString()); //得到这个用户的全部信息 UserInfo a = Discuz.Forum.Users.GetUserInfo(uid); //打印出来看看对不对。 //Response.Write(a.Username); this.denglu.Visible = false; this.tuichu.Visible = true; Label1.Text = a.Username ; } else { this.denglu.Visible = true; this.tuichu.Visible = false; } } //登录 protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { string username = txtUserName.Text.Trim(); string password = txtPassWord.Text.Trim(); string apikey = "7c48cc03caede883471b42e5e9b533d8";//有Discuz后台管理扩展->通行证设置获得 string secret = "2ad48b05ac6cf0025011600d4e658db5";//同上 string url = "http://bbs.xxxx.com/";//你的bbs路径 string cookieDomain = "http://xxxx.com/";//你的域名 DiscuzSession ds = new DiscuzSession(apikey, secret, url); int id = ds.GetUserID(username);//根据用户名获取用户ID //用户名存在 if (id > 0) { //取得用户数据库中的密码 string dbpassword=ds.GetUserInfo(id).Password; //判断数据库中的密码和输入的密码是否一致 if (dbpassword == FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5").ToLower()) { //输入密码正确,则登录 ds.Login(id, password, true, 10000, cookieDomain); Discuz.Config.GeneralConfigInfo config = Discuz.Config.GeneralConfigs.GetConfig(); //删除之前的错误登录信息 LoginLogs.DeleteLoginLog(DNTRequest.GetIP()); //根据积分公式刷新用户总积分 UserCredits.UpdateUserCredits(id); //写入用户登录后的cookie ForumUtils.WriteUserCookie(id, Utils.StrToInt(DNTRequest.GetString("expires"), -1), config.Passwordkey, DNTRequest.GetInt("templateid", 0), DNTRequest.GetInt("loginmode", -1)); //更新用户最后动作,如不需要可不执行 //OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0, config.Onlinetimeout); //更新该用户最后访问时间 // Users.UpdateUserLastvisit(id, DNTRequest.GetIP()); this.denglu.Visible = false; this.tuichu.Visible = true; Label1.Text = ds.GetUserInfo(id).UserName; } else { //密码输入错误 Label1.Text = "密码输入错误"; } } else { Label1.Text = "用户名不存在"; } } //退出 protected void ImageButton3_Click(object sender, ImageClickEventArgs e) { //string username = txtUserName.Text.Trim(); //string password = txtPassWord.Text.Trim(); if (Request.Cookies["dnt"] != null && Request.Cookies["dnt"].Values["userid"] != null) { int uid = Convert.ToInt32(Request.Cookies["dnt"].Values["userid"].ToString()); UserInfo a = Discuz.Forum.Users.GetUserInfo(uid); string apikey = "7c48cc03caede883471b42e5e9b533d8";//有Discuz后台管理扩展->通行证设置获得 string secret = "2ad48b05ac6cf0025011600d4e658db5";//同上 string url = "http://bbs.xxxx.com/";//你的bbs路径 string cookieDomain = "http://xxxx.com/";//你的域名 DiscuzSession ds = new DiscuzSession(apikey, secret, url); ds.Logout(cookieDomain); int id = ds.GetUserID(a.Username); int olid = OnlineUsers.GetOlidByUid(id); OnlineUsers.DeleteRows(olid); ForumUtils.ClearUserCookie(); this.denglu.Visible = true; this.tuichu.Visible = false; } }
相关文章
- 一题多解,ASP.NET Core应用启动初始化的N种方案[下篇]
- ASP.Net MVC视图间的跳转
- .net 温故知新:【8】.NET 中的配置从xml转向json
- .net 温故知新:【10】.NET ORM框架EFCore使用入门之CodeFirs、DBFirst
- 统治扩散模型的U-Net要被取代了,谢赛宁等引入Transformer提出DiT
- 【Linux 内核】Linux 内核源码目录说明 ③ ( lib 目录 | LICENSES 目录 | mm 目录 | net 目录 | samples 目录 | scripts 目录 )
- 基于.NET与MySQL的网站开发指南(.netmysql)
- 联手开发:.NET与Oracle的合作之路(.net和oracle)
- MySQL与VB.NET的数据库开发实践(mysqlvb.net)
- .Net程序开发利用Redis提高效率(.net使用redis)
- Linux上安装.NET:提高开发效率,拓展技术栈(linux安装.net)
- .net下的数据库连接SQLServer驱动在.NET平台下的数据库连接简明介绍(sqlserver驱动在)
- C与MySQL融合打造优秀的网站开发体验(c net mysql)
- 使用Net实现Oracle数据库的快速导入(net导入oracle)
- 快速搭建 NET 项目,用 MySQL 配置环境(.net 配置mysql)
- NET环境下 MySQL数据库应用实践(.net配合 mysql)
- 使用NET来连接MySQL数据库的简单方法(.net怎么连mysql)
- NET和MySQL的无缝搭配实现创新的技术路径(.net mysql支持)
- Net平台下MySQL数据库操作实践(.net mysql操作)
- NET 与 MySQL 结合能实现优雅的数据事务处理(.net MySQL事物)
- 探索Oracle中NET位置的背后秘密(oracle中net位置)
- ASP.NET用户多次登录的解决方法
- asp.net需要登陆的网站上下载网页源代码和文件
- asp.net数据库连接池浅析
- asp.net下用Aspose.Wordsfor.NET动态生成word文档中的数据表格的方法
- 基于ASP.NET的lucene.net全文搜索实现步骤
- .NET之后台用户权限管理实现
- asp.net实现删除DataGrid的记录时弹出提示信息