您现在的位置是:首页 > 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;
}
}
本文标签:
很赞哦! ()
相关教程
图文教程
Discuz的NT企业版Sphinx全文搜索功能介绍
作为DiscuzNT企业版中的一员,在设计企业级搜索架构之初,就考虑了海量数量,准实时索引更新,并发访问,安装布署等诸多方面。目前在生产环境下被广泛使用的开源搜索引擎中
Discuz的authcode函数注释
Discuz函数中最经典的函数是authcode函数,因为supesite,UCenterHome,UCenter,Discuz X都使用了这个函数进行加密
discuz是什么?有什么作用?
discuz是一套通用的社区论坛软件系统,是一个采用PHP和MySQL等其他多种数据库构建的 论坛解决方案。使用discuz,用户可以在不需要任何编程的基
Discuz添加自定义板块和分类的方法
Discuz如何添加自定义板块和分类?这个问题其实涉及到Discuz论坛系统的灵活性和可扩展性。添加自定义板块和分类不仅能让你的论坛更具个性化,还能更好地组织内容,提升用户体验。
相关源码
-
(PC+WAP)蓝色电缆桥架五金钢结构机械PbootCMS模板下载采用PC与WAP双端适配设计,满足桌面设备和移动端访问需求。专注服务于电缆桥架、钢结构及五金机械制造领域,通过结构化布局展示产品特性与技术参数,后台数据一体化管理提升内容维护效率。查看源码 -
pbootcms模板PC+WAP娱乐新闻资讯类博客网站源码该模板基于PbootCMS内核开发,专为娱乐新闻、健康生活类资讯网站设计,同时支持快速适配其他行业(如企业官网、博客门户等),仅需替换图文内容即可完成转型。查看源码 -
(自适应响应式)家电维修清晰服务网站pbootcms模板免费下载本模板基于PbootCMS内核开发,为维修服务类企业打造,特别适合家电维修、设备维护等行业使用。通过简洁直观的界面设计,帮助企业快速搭建专业级服务平台,实现线上业务高效管理。查看源码 -
帝国cms大气淘宝客网站源码带手机版带火车头采集本款创意礼物导购网站模板为礼物类电商平台设计,采用清爽简约的界面风格,具备完善的商品导购功能。系统支持在文章攻略中灵活插入商品购买链接,实现内容与电商的结合。查看源码 -
(自适应响应式)蓝色环保机械设备网站pbootcms模板HTML5源码下载基于PbootCMS的生态环境技术展示平台,通过内容调整可应用于新能源设备、污水处理、空气净化等环保相关领域。设备参数采用对比表格展示,技术原理支持图文混排;查看源码 -
(PC+WAP)压缩机离心风机红色机械设备营销型网站pbootcms模板基于PbootCMS开发的压缩机/离心风机专用模板,助力机械设备企业构建高效营销平台;模板可编辑压缩机参数表、风机性能曲线等专业展示模块查看源码
| 分享笔记 (共有 篇笔记) |
