Esempio n. 1
0
        //检查注册频率
        private IActionResult checkRegRates(string vcode, string vregval, string regip)
        {
            string key = "ip_regrates_" + regip;
            string c   = UrsHelper.Cache_GetObj(key) as string;

            if (false == string.IsNullOrEmpty(c))
            {
                RegCompact prev = RegCompact.Parse(c);
                if (prev.isOver())
                {
                    //如果传递了vcode和vregval 说明提交了验证码
                    if (vcode.Length == 4 && vregval.Length > 0)
                    {
                        //先判断vcode是否被重用了
                        if (UrsHelper.Cache_GetObj(string.Format("cache_reg_code_{0}_ip_{1}", vcode, regip)) != null)
                        {
                            return(this.FuncResult(new APIReturn(10102, "请刷新验证码")));
                        }
                        this.regcode = vcode;
                        return(decRegVal(vregval, vcode, regip));
                    }
                    else
                    {
                        return(createVCode(regip));
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
        void addRegSuc(string regip)
        {
            RegCompact prev;

            string key = "ip_regrates_" + regip;

            string c = UrsHelper.Cache_GetObj(key) as string;

            if (false == string.IsNullOrEmpty(c))
            {
                prev = RegCompact.Parse(c);
                prev.update(DateTime.Now);
            }
            else
            {
                prev = new RegCompact(DateTime.Now);
            }
            UrsHelper.Cache_SetObj(key, prev.ToString(), 60, 0);

            //一旦通过验证码完成注册,则将此码和ip一起作为key,添加缓存,下次提交验证码时判断,
            //是否有此session,有则怀疑重复提交相同验证码,10分钟都不允许同ip提交相同验证码,会误伤
            if (!string.IsNullOrWhiteSpace(this.regcode) && this.regcode.Length == 4)
            {
                UrsHelper.Cache_SetObj(string.Format("cache_reg_code_{0}_ip_{1}", this.regcode, regip), 1, 10, 0);
            }
        }
Esempio n. 3
0
        public IActionResult func_reg(RegModel regModel)
        {
            string acct          = regModel.email;
            string pass          = regModel.pass ?? string.Empty;
            string encrypt       = regModel.encrypt ?? string.Empty;
            bool   passisencrypt = regModel.encrypt == "True" || regModel.encrypt == "true";
            string tname         = regModel.tname ?? string.Empty;
            string mobile        = regModel.mobile ?? string.Empty;
            string idcard        = regModel.idcard ?? string.Empty;
            string gatesrc       = regModel.gatesrc ?? "urs";
            string pstype        = regModel.pstype ?? "game";
            int    qq            = regModel.qq;
            string ipstr         = regModel.ip ?? string.Empty;
            string regip         = ipstr;
            bool   hasip         = !string.IsNullOrWhiteSpace(ipstr) && ipstr.Length > 7;
            int    ip            = ip2long(ipstr);

            string          ipkey        = string.Format("check-reg-ip-{0}", ip);
            object          obj          = UrsHelper.Cache_GetObj(ipkey);
            List <DateTime> li_ipreglist = new List <DateTime>();

            if (obj != null && obj is List <DateTime> )
            {
                li_ipreglist = (List <DateTime>)obj;
                int regcount = 0;
                for (int i = li_ipreglist.Count - 1; i >= 0; i--)
                {
                    DateTime d = li_ipreglist[i];
                    if (Math.Abs((DateTime.Now - d).TotalSeconds) > 900)
                    {
                        li_ipreglist.RemoveAt(i);
                    }
                    else
                    {
                        regcount++;
                    }
                }
                if (regcount >= 101)//放得较宽,以防如3G网之类的可能有问题
                {
                    this.FuncResult(new APIReturn(10320, "注册频繁"));
                }
            }

            string vcode = regModel.vcode;

            if (regModel.ismodenopass)
            {
                pass          = "******";
                passisencrypt = true;
            }
            string passmd5 = passisencrypt ? pass : UrsHelper.MD5(pass);

            if (passmd5 == "0ab7dea79b1de3d0816f8b5cbbb36367")
            {
                //Operator.CHT_ExtData["ismodenopass"] = true;
                regModel.ismodenopass = true;
            }

            WebParams webParans = new WebParams(this.Request);
            var       dicValues = webParans.Where(e => e.Key.StartsWith("extarg_")).ToDictionary(e => e.Key, e => e.Value);
            Hashtable cht_args  = new Hashtable(dicValues);

            if (qq <= 0)
            {
                qq = 0;
            }
            string friendname = UrsHelper.Lib_Friend_GetName(acct);

            if (friendname.Length > 0)
            {
                this.FuncResult(new APIReturn(10350, string.Format("{0}帐号不能在这里进行注册操作", friendname)));
            }

            string[] acctspt = acct.Split('@');
            string   domain  = acctspt[1].ToLower();

            if (domain.EndsWith("2980.com") && domain != "2980.com" ||
                domain == "2925.com" ||
                acct.ToLower().IndexOf("@henhaoji.com") != -1 ||
                acct.ToLower().IndexOf("@duoyi.com") != -1)
            {
                this.FuncResult(new APIReturn(10355, "该类邮箱不支持注册,请选用其他邮箱"));
            }
            if (friendname != string.Empty)
            {
                this.FuncResult(new APIReturn(10326, string.Format("{0}帐号无需注册,可直接登录", friendname)));
            }
            if (!isemail(acct))
            {
                this.FuncResult(new APIReturn(10302, "帐号格式错误"));
            }
            if (!isvpass(pass, passisencrypt))
            {
                this.FuncResult(new APIReturn(10305, "密码格式错误"));
            }
            if (!string.IsNullOrWhiteSpace(idcard) && idcard.Length > 0 && !isidcard(idcard))
            {
                this.FuncResult(new APIReturn(10711, "身份证格式错误"));
            }
            if (!string.IsNullOrWhiteSpace(tname) && tname.Length > 0 && !isvname(tname))
            {
                this.FuncResult(new APIReturn(10720, "姓名格式错误"));
            }
            if (!string.IsNullOrWhiteSpace(mobile) && mobile.Length >= 1 && !IsMobile(mobile))
            {
                this.FuncResult(new APIReturn(10701, "手机号格式错误"));
            }
            if (regModel.qq.ToString().Length >= 5 && (qq <= 0))
            {
                this.FuncResult(new APIReturn(10730, "QQ号格式错误"));
            }
            if (passisencrypt)
            {
                if (pass.Length != 32)
                {
                    this.FuncResult(new APIReturn(10000, $"参数错误pass={pass}"));
                }
                pass = UrsHelper.MD5(pass.Substring(7, 16)).Substring(3, 16);
            }
            return(func_exec_reg(regModel, false, ip, acct, pass, passisencrypt, tname, idcard, mobile, qq, gatesrc, pstype, cht_args.ToJson(), regip));
        }
Esempio n. 4
0
        private IActionResult func_exec_reg(RegModel regModel, bool isfriend, int ip, string acct, string pass, bool passismyencrypt, string tname, string idcard, string mobile, int qq, string gatesrc, string pstype, string extinfo, string regip)
        {
            //配置控制,是否需要检查注册时的验证码,一段时间之后应去掉此项判断,否则非公司正常产品的gate就绕过此内容
            if (DC2Conf.RegvcodeProducts.Contains(gatesrc) && DC2Conf.RegvcodeEnable)
            {
                //2016-1-20 对于163邮箱,没有传验证码的必须传验证码
                if (acct.ToLower().EndsWith("163.com"))
                {
                    if (string.IsNullOrEmpty(regModel.vcode) && string.IsNullOrEmpty(regModel.vregval))
                    {
                        return(createVCode(regip));
                    }
                    else
                    {
                        var retValue = decRegVal(regModel.vregval, regModel.vcode, regip);
                        if (retValue != null)
                        {
                            return(retValue);
                        }
                    }
                }
                else
                {
                    var retValue = checkRegRates(regModel.vcode, regModel.vregval, regip);
                    if (retValue != null)
                    {
                        return(retValue);
                    }
                }
            }

            UrsacctInfo userInfo = Ursacct.GetItem(acct);

            if (userInfo != null)
            {
                Hashtable htbData = new Hashtable();
                htbData.Add("number", userInfo.AcctNumber.Value);
                return(this.FuncResult(new APIReturn(10303, "帐号已存在", htbData)));
            }

            DCClass    dcc     = new DCClass();
            DicDCValue dcValue = dcc.Acct_Register(regModel, isfriend, ip, acct, pass, passismyencrypt, tname, idcard, mobile, qq, gatesrc, pstype);

            if (dcValue.Code == 0)
            {
                int number = dcValue["number"].ToInt();
                Ursuser.CreateUser(number, acct, qq, mobile, idcard, extinfo);
                Hashtable cht_rcdata = new Hashtable();
                cht_rcdata["number"] = number;
                //添加缓存
                if (ip != 0 && ip != -1)
                {
                    string          ipkey        = string.Format("check-reg-ip-{0}", ip);
                    object          obj          = UrsHelper.Cache_GetObj(ipkey);
                    List <DateTime> li_ipreglist = new List <DateTime>();
                    if (obj != null && obj is List <DateTime> )
                    {
                        li_ipreglist = (List <DateTime>)obj;
                    }
                    li_ipreglist.Add(DateTime.Now);
                    UrsHelper.Cache_SetObj(ipkey, li_ipreglist);
                }
                addRegSuc(regip);
                cht_rcdata["email"]    = regModel.email;
                cht_rcdata["mailhost"] = "http://mail" + regModel.email.Substring(regModel.email.IndexOf('@'), regModel.email.Length - regModel.email.IndexOf('@'));
                return(this.FuncResult(new APIReturn(0, "注册成功", cht_rcdata)));
            }
            else if (dcValue.Code == 65)
            {
                return(this.FuncResult(new APIReturn(10303, "帐号已存在")));
            }
            else
            {
                return(this.FuncResult(new APIReturn(10306, $"注册失败({dcValue.Code})")));
            }
        }