您现在的位置是:首页 > cms教程 > Discuz教程Discuz教程

discuz的NT3.5论坛整合.net网站用户登录退出的方法

文子隐2025-06-29Discuz教程已有人查阅

导读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.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;
}
}

本文标签:

很赞哦! ()

相关源码

  • (自适应)绿色农业机械设备农场网站源码下载为现代农业机械领域打造的响应式网站模板,采用PbootCMS内核开发,数据实时同步后台管理。通过简洁大气的视觉设计,有效展示农机产品技术参数与应用场景,帮助客户快速建立专业数字化形象。查看源码
  • pbootcms网站网络公司个人作品展示类网站源码(自适应)为网站建设公司、网络服务企业打造的响应式门户解决方案,基于PbootCMS内核深度开发。采用前沿自适应架构,无缝适配手机端交互与PC端展示需求。查看源码
  • 帝国CMS中小学生知识点试题练习题考试源码下载基于帝国CMS后台管理系统,支持在线修改联系信息、网站参数等配置,操作流程简洁明了。专注于中小学教育领域,集成知识点总结、试题练习、考试资讯等学习资源,为师生提供全面的在线学习支持与服务。查看源码
  • (自适应)工业机械制造设备网站pbootcms模板下载为机械制造、工业设备类企业设计,特别适合各类机械设备、生产线、工业自动化产品展示。采用响应式技术,确保在不同设备上都能清晰展示机械产品的技术参数和细节特点。查看源码
  • (自适应手机端)seo博客网站模板新闻资讯网站源码下载本模板为SEO博客及新闻资讯类平台深度定制,采用PbootCMS内核开发。通过模块化设计实现多行业快速适配,仅需替换图文内容即可转型为医疗、教育、科技等领域网站。响应式布局确保在手机、平板等设备上获得一致浏览体验。查看源码
  • (自适应)宽屏农业机械农耕设备类网站pbootcms模板免费下载为农机企业打造的现代化响应式网站模板,自动适配电脑、平板和手机,浏览体验一致,独立页面SEO设置,提升搜索引擎可见度。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐