예제 #1
0
        /// <summary>
        /// 验证用户,通过网络
        /// </summary>
        /// <param name="netname"></param>
        /// <param name="netpass"></param>
        /// <param name="hdinfo"></param>
        /// <returns></returns>
        protected ModelMember getUser(string netname, string netpass, string hdinfo)
        {
#if DEBUG
            member.netname             = "调试模式";
            member.group               = "商业授权用户";
            member.sitenum             = 9999;
            member.IS_X_WordPressBuild = true;
            member.IS_X_PostKing       = true;
            member.userMoney           = 9999;
            return(Login_Base.member);
#endif
            string           path    = Application.StartupPath + "\\Config\\RenZheMember.txt";
            string           html    = "";
            DbTools          db      = new DbTools();
            CookieCollection cookies = new CookieCollection();

            try {
                object obj = db.Read(path, "VCDS");
                if (obj != null)
                {
                    member = (ModelMember)obj;
                }

                EchoHelper.Echo("连接【忍者软件】用户服务端,进行通信。此过程稍慢,请稍候...", "系统登录", EchoHelper.EchoType.任务信息);

                //发现有不符的情况,将进行登录验证。
                if (member.logintime.Date < DateTime.Now.Date || member.netpass != netpass || member.netname != netname || member.hdinfo != HardWare.getHardCode())
                {
                    string purl  = "http://www.renzhe.org/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1";
                    string pdata = "fastloginfield=username&username="******"&password="******"&quickforward=yes&handlekey=ls";
                    html = new xkHttp().httpPost(purl, pdata, ref cookies, purl, Encoding.GetEncoding("utf-8"));

                    if (html.Contains(">window.location.href='"))
                    {
                        wait.ShowMsg("4/10 您的账户、密码验证成功!");
                        EchoHelper.Echo("论坛账户、密码验证成功!", "系统登录", EchoHelper.EchoType.任务信息);
                        purl = "http://www.renzhe.org/home.php?mod=spacecp&ac=credit";
                        html = new xkHttp().httpGET(purl, ref cookies);
                        if (html.Contains("[ 点击这里返回上一页 ]"))
                        {
                            EchoHelper.Echo("忍者服务端维护,暂时关闭,请稍后再试...", "系统登录", EchoHelper.EchoType.错误信息);
                            return(member);
                        }
                        if (html.Contains("您需要先登录才能继续本操作"))
                        {
                            EchoHelper.Echo("您的账号异常,请手工登录论坛检查账户问题!", "系统登录", EchoHelper.EchoType.错误信息);
                            return(member);
                        }
                        if (html.Contains("抱歉,您的 IP 地址不在被允许,或您的账号被禁用,无法访问本站点"))
                        {
                            EchoHelper.Echo("抱歉,您的 IP 地址不在被允许,或您的账号被禁用,无法访问本站点!", "系统登录", EchoHelper.EchoType.错误信息);
                            return(member);
                        }

                        wait.ShowMsg("5/10 您的用户基本信息,获取成功!");
                        EchoHelper.Echo("您的用户基本信息,获取成功!", "系统登录", EchoHelper.EchoType.任务信息);
                        member.UID           = RegexHelper.getHtmlRegexText(html, "{discuz_uid = '(.*?)'}");
                        member.netname       = RegexHelper.getHtmlRegexText(html, "{title=\"访问我的空间\">(.*?)</a>}");
                        member.sitenum       = Convert.ToInt32(RegexHelper.getHtmlRegexText(html, "{站点数:</em>(.*?) </li>}"));
                        member.group         = RegexHelper.getHtmlRegexText(html, "{showUpgradeinfo\\)\">(.*?)</a>}");
                        member.userMoney     = Convert.ToInt32(RegexHelper.getHtmlRegexText(html, "{金币:</em>(.*?)  &nbsp;}"));
                        member.formhash      = RegexHelper.getHtmlRegexText(html, "{formhash=(.*?)\">退出</a>}");
                        member.cookies       = cookies;
                        member.netpass       = netpass;
                        member.logintime     = DateTime.Now;
                        member.hdinfo        = HardWare.getHardCode();
                        member.IS_X_PostKing = true;
                        EchoHelper.Echo("链接服务端,判断应用授权状态...", "系统登录", EchoHelper.EchoType.任务信息);
                        wait.ShowMsg("6/10 链接服务端,判断应用授权状态!");
                    }
                    else
                    {
                        wait.ShowMsg("用户验证失败...");
                        string result = "未知,请重试,登录论坛联系管理员。www.renzhe.org";
                        if (html.Contains("登录失败"))
                        {
                            result = "请核对您的用户名密码!登录论坛联系管理员。www.renzhe.org";
                        }
                        if (html.Contains("showWindow('login', 'member.php?mod=logging&action="))
                        {
                            result = "发现安全问题,清除您的安全问题后,再尝试!www.renzhe.org";
                        }
                        if (html.Contains("密码错误次数过多"))
                        {
                            result = "密码错误次数过多,稍后再试!登录论坛联系管理员。www.renzhe.org";
                        }
                        if (html.Contains("无法解析此远程名称"))
                        {
                            result = "无法解析www.renzhe.org,请检查您的网络,稍后再试";
                        }

                        member.IS_X_PostKing       = false;
                        member.IS_X_WordPressBuild = false;

                        EchoHelper.Echo("登录失败:" + result, "系统登录", EchoHelper.EchoType.错误信息);
                        return(member);
                    }
                }
                else
                {
                    wait.ShowMsg("7/10 发现本地密钥,进行快捷登录...");
                    EchoHelper.Echo("发现本地登录密钥文件,进行验证,请稍后...", "系统登录", EchoHelper.EchoType.任务信息);
                }

#if !DEBUG
                //向服务端提交member序列化的类,然后验证是否为登录成功的状态。
                ValidateUser(ref member);
#else
                //ValidateUser(ref member);
#endif

                ini.up("登录账户密码", "INFO", member.netname);
                if (member.IS_X_PostKing == false)
                {
                    member.logintime = DateTime.Now.AddDays(-111);
                    FilesHelper.DeleteFile(path);
                }
                else
                {
                    wait.ShowMsg("8/10 恭喜,您的密钥经服务端验证成功!");
                    EchoHelper.Echo("恭喜,您的本地密钥,经服务端验证成功,通信一切正常!", "系统登录", EchoHelper.EchoType.任务信息);
                }
            } catch (Exception ex) {
                FilesHelper.DeleteFile(path);
                EchoHelper.Echo("与服务端通信失败!" + ex.Message, "系统登录", EchoHelper.EchoType.异常信息);
            } finally {
                if (member.group.Contains("商业"))
                {
                    member.IS_X_WordPressBuild = true;
                }

                if (member.IS_X_PostKing == true)
                {
                    wait.ShowMsg("9/10 密钥已保存,下次可快捷登录!");
                    Thread.Sleep(1200);
                    EchoHelper.Echo("您的本地密钥已保存,下次可快捷登录!", "系统登录", EchoHelper.EchoType.任务信息);
                    db.Save(path, "VCDS", member);
                }
            }
            return(Login_Base.member);
        }