Discuz! Passport 通行证整合(9)

protected void Page_Load(object sender, EventArgs e){
        dzForward = Request.QueryString["forward"];
        if (Request.QueryString["act"] == "logout") logout();
        if(Session["username"]!=null) Response.Write(Session["username"].ToString()+ "登陆成功! <a href=https://www.jb51.net/article/\"default.aspx?act=logout\">点击这里退出登陆</a> <a href="https://www.jb51.net/+dzUrl+" target=_blank>访问论坛</a><br>");
    }

protected void logout(){
        Session["username"] = null;
        dzForward           = Request.QueryString["forward"];//获取返回地址
        if (dzForward == "") dzForward = webUrl;//如果返回地址为空,则返回设置的页
        dzVerify            = md5("logout" + dzForward + dzPassportKey);
        dzForward           = Server.UrlEncode(dzForward);
        Response.Redirect(dzUrl + "api/passport.php?action=logout&auth=https://www.jb51.net/article/&forward=" + dzForward + "&verify=" + dzVerify);

    }


    protected void Button1_Click(object sender, EventArgs e){
        string postUsername;
        string postPwd;
        postUsername        = username.Text.ToString().Trim();
        postPwd             = password.Text.ToString();

if(postUsername=="admin" && postPwd=="123456"){
            Session["username"]=postUsername;//设置主站自身的cookie或session;

//---------------------------passport注册或登陆整合开始-----------------------------
            string memberInfo = "username=" + postUsername
                        + "&password=" + md5(postPwd)
                        + "&time="+ time()//获取当前时间与格林威治的秒差
                        + "&email="+"abc@abc.com";//需要email的值,实际整合通常情况是从数据库里获取用户email
            dzAuth          = passport_encrypt(memberInfo , dzPassportKey);
            dzForward       = forward.Value.ToString().Trim();//获取返回地址
            if(dzForward=="") dzForward = webUrl;//如果返回地址为空,则返回设置的页
            dzVerify        = md5("login" + dzAuth + dzForward + dzPassportKey);
            dzAuth          = Server.UrlEncode(dzAuth);
            dzForward       = Server.UrlEncode(dzForward);
            Response.Redirect(dzUrl + "api/passport.php?action=login&auth=" + dzAuth + "&forward=" + dzForward + "&verify=" + dzVerify);
            //---------------------------passport注册或登陆整合结束-----------------------------
        }else Response.Write("登陆失败<br>");
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a6b433df30aff4795dbf0d07a5abf20e.html