Пример #1
0
        protected override void OnInit(EventArgs e)
        {
            if (!DiscuzCloud.GetCloudServiceEnableStatus("connect"))
            {
                base.AddErrLine("QQ登录功能已关闭");
                return;
            }
            string a;

            if ((a = this.action) != null)
            {
                if (!(a == "access"))
                {
                    if (!(a == "bind"))
                    {
                        if (a == "unbind")
                        {
                            if (this.userid < 1)
                            {
                                base.AddErrLine("未登录用户无法进行该操作");
                                return;
                            }
                            this.userconnectinfo = DiscuzCloud.GetUserConnectInfo(this.userid);
                            if (this.userconnectinfo == null)
                            {
                                base.AddErrLine("您并没有绑定过QQ,不需要执行该操作");
                                return;
                            }
                            if (this.ispost)
                            {
                                if (!this.userconnectinfo.IsSetPassword)
                                {
                                    string @string = DNTRequest.GetString("newpasswd");
                                    if (string.IsNullOrEmpty(@string))
                                    {
                                        base.AddErrLine("您必须为帐号设置新密码才能解除绑定");
                                        return;
                                    }
                                    if (@string.Length < 6)
                                    {
                                        base.AddErrLine("密码不得少于6个字符");
                                        return;
                                    }
                                    if (@string != DNTRequest.GetString("confirmpasswd"))
                                    {
                                        base.AddErrLine("两次输入的新密码不一致");
                                        return;
                                    }
                                    var userInfo = Users.GetUserInfo(this.userid);
                                    userInfo.Password = @string;
                                    Users.ResetPassword(userInfo);
                                    Sync.UpdatePassword(userInfo.Name, userInfo.Password, "");
                                    if (!Utils.StrIsNullOrEmpty(DNTRequest.GetString("changesecques")))
                                    {
                                        Users.UpdateUserSecques(this.userid, DNTRequest.GetInt("question", 0), DNTRequest.GetString("answer"));
                                    }
                                    ForumUtils.WriteCookie("password", ForumUtils.SetCookiePassword(userInfo.Password, this.config.Passwordkey));
                                    OnlineUsers.UpdatePassword(this.olid, userInfo.Password);
                                }
                                DiscuzCloud.UnbindUserConnectInfo(this.userconnectinfo.OpenId);
                                ConnectbindLog userConnectBindLog = DiscuzCloud.GetUserConnectBindLog(this.userconnectinfo.OpenId);
                                if (userConnectBindLog != null)
                                {
                                    userConnectBindLog.Type = 2;
                                    DiscuzCloud.UpdateUserConnectBindLog(userConnectBindLog);
                                }
                                base.AddMsgLine("解绑成功");
                                string text = Utils.UrlDecode(ForumUtils.GetReUrl());
                                base.SetUrl((text.IndexOf("register.aspx") < 0) ? text : (this.forumpath + "index.aspx"));
                                base.SetMetaRefresh();
                                return;
                            }
                            return;
                        }
                    }
                    else
                    {
                        if (!this.ispost)
                        {
                            return;
                        }
                        if (DNTRequest.GetString("bind_type") == "new")
                        {
                            this.RegisterAndBind();
                            return;
                        }
                        if (this.userid < 0)
                        {
                            this.BindForumExistedUser();
                            return;
                        }
                        this.BindLoginedUser();
                        return;
                    }
                }
                else
                {
                    if (!this.CheckCallbackSignature(DNTRequest.GetString("con_sig")))
                    {
                        base.AddErrLine("非法请求");
                        return;
                    }
                    OAuthAccessTokenInfo connectAccessTokenInfo = DiscuzCloud.GetConnectAccessTokenInfo();
                    if (connectAccessTokenInfo == null)
                    {
                        base.AddErrLine("QQ登录过程中出现异常,请尝试再次登录");
                        return;
                    }
                    userconnectinfo = DiscuzCloud.GetUserConnectInfo(connectAccessTokenInfo.Openid);
                    if (userconnectinfo == null)
                    {
                        userconnectinfo        = new UserConnect();
                        userconnectinfo.OpenId = connectAccessTokenInfo.Openid;
                        userconnectinfo.Token  = connectAccessTokenInfo.Token;
                        userconnectinfo.Secret = connectAccessTokenInfo.Secret;
                        userconnectinfo.AllowVisitQQUserInfo = DNTRequest.GetInt("con_is_user_info", 0) != 0;
                        userconnectinfo.AllowPushFeed        = DNTRequest.GetInt("con_is_feed", 0) != 0;
                        userconnectinfo.CallbackInfo         = usedusernames + "&" + birthday + "&" + gender + "&" + email;
                        //DiscuzCloud.CreateUserConnectInfo(this.userconnectinfo);
                        userconnectinfo.Insert();
                    }
                    else
                    {
                        if (this.userconnectinfo.Uid > 0)
                        {
                            if (this.userid > 0)
                            {
                                base.SetBackLink("index.aspx");
                                base.AddErrLine((this.userconnectinfo.Uid != this.userid) ? "该QQ已经绑定了其他帐号" : "该QQ用户已登录");
                                return;
                            }
                            IUser  shortUserInfo = Discuz.Entity.User.FindByID(this.userconnectinfo.Uid);
                            string url;
                            if (shortUserInfo == null)
                            {
                                DiscuzCloud.UnbindUserConnectInfo(this.userconnectinfo.OpenId);
                                url = HttpContext.Current.Request.RawUrl;
                            }
                            else
                            {
                                url = HttpContext.Current.Request.QueryString["url"];
                                if (string.IsNullOrEmpty(url))
                                {
                                    url = this.forumpath + "index.aspx";
                                }
                                if (connectAccessTokenInfo.Token != this.userconnectinfo.Token || connectAccessTokenInfo.Secret != this.userconnectinfo.Secret)
                                {
                                    this.userconnectinfo.Token  = connectAccessTokenInfo.Token;
                                    this.userconnectinfo.Secret = connectAccessTokenInfo.Secret;
                                    DiscuzCloud.UpdateUserConnectInfo(this.userconnectinfo);
                                }
                                this.LoginUser(shortUserInfo);
                            }
                            HttpContext.Current.Response.Redirect(url);
                            HttpContext.Current.ApplicationInstance.CompleteRequest();
                        }
                        else
                        {
                            string[] array = this.userconnectinfo.CallbackInfo.Split('&');
                            if (array.Length == 4)
                            {
                                this.usedusernames = (string.IsNullOrEmpty(this.usedusernames) ? array[0] : this.usedusernames);
                                this.birthday      = (string.IsNullOrEmpty(this.birthday) ? array[1] : this.birthday);
                                this.gender        = ((this.gender == 0) ? Utils.StrToInt(array[2], 0) : this.gender);
                                this.email         = (string.IsNullOrEmpty(this.email) ? array[3] : this.email);
                            }
                        }
                    }
                    ConnectbindLog userConnectBindLog2 = DiscuzCloud.GetUserConnectBindLog(this.userconnectinfo.OpenId);
                    this.isbindoverflow = (userConnectBindLog2 != null && this.cloudconfig.Maxuserbindcount > 0 && userConnectBindLog2.BindCount >= this.cloudconfig.Maxuserbindcount);
                    this.allowreg       = (this.config.Regstatus != 0 && this.cloudconfig.Allowconnectregister == 1 && !this.isbindoverflow);
                    this.connectswitch  = ((this.allowreg && this.userid < 0) ? 1 : 2);
                    byte[] bytes = Convert.FromBase64String(this.usedusernames);
                    this.usedusernames = Encoding.Default.GetString(bytes);
                    this.avatarurl     = string.Format("http://avatar.connect.discuz.qq.com/{0}/{1}", DiscuzCloudConfigInfo.Current.Connectappid, this.userconnectinfo.OpenId);
                    this.openid        = this.userconnectinfo.OpenId;
                    return;
                }
            }
            if (this.isbindconnect)
            {
                base.AddErrLine("用户已登录");
                return;
            }
            HttpContext.Current.Response.Redirect(DiscuzCloud.GetConnectLoginPageUrl(this.userid));
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }