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, true10000, 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;

            }
        }
  • 相关阅读:
    【搜索引擎】Solr最新安装以及通过关系型数据库(MySQL,Oracle,PostgreSQL)导入数据
    【搜索引擎】SOLR VS Elasticsearch(2019技术选型参考)
    【Java源码】集合类-优先队列PriorityQueue
    【Java源码】树-概述
    Go语言调度器之创建main goroutine(13)
    Go语言goroutine调度器初始化(12)
    Go语言goroutine调度器概述(11)
    线程本地存储及实现原理
    操作系统线程及线程调度
    系统调用
  • 原文地址:https://www.cnblogs.com/feifei/p/2455739.html
Copyright © 2011-2022 走看看