zoukankan      html  css  js  c++  java
  • discuz !NT 3.5 论坛整合 .net 网站用户登录,退出

    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;
    
            }
        }
    

      

  • 相关阅读:
    golang 引用相对路径package
    LiteIDE 在 Windows 下为 Go 语言添加智能提示代码补全
    C#代码实现把网页文件保存为mht文件
    AE开发中关于 “无法嵌入互操作类型.........请改用适用的接口”问题的解决方法
    Windows下visual studio code搭建golang开发环境
    Eclipse配置开发Go的插件——Goclipse
    go语言条件语句 if else
    Go语言基础:method
    GO语言基础之method
    go中的接口
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/4840711.html
Copyright © 2011-2022 走看看