コード例 #1
0
        public static StringHash Create(DataSource ds, string s, int type, int timespan)
        {
            StringHash hash = Db <StringHash> .Query(ds)
                              .Select()
                              .Where(W("Type", type) & W("Hash", s))
                              .First <StringHash>();

            if (hash != null)
            {
                if (hash.CreationDate.AddSeconds(timespan) > DateTime.Now)
                {
                    return(null);
                }
                hash.CreationDate = DateTime.Now;
                if (hash.Update(ds) == DataStatus.Success)
                {
                    return(hash);
                }
            }
            else
            {
                hash = new StringHash()
                {
                    Type = type, Hash = s, CreationDate = DateTime.Now
                };
                if (hash.Insert(ds) == DataStatus.Success)
                {
                    return(hash);
                }
            }
            return(null);
        }
コード例 #2
0
        public static bool Sms(string name, int type, DataSource ds)
        {
            try
            {
                PassportSection section = PassportSection.GetSection();
                if (!section.VerifyMobile)
                {
                    throw new Exception();
                }

                HttpRequest Request = HttpContext.Current.Request;
                string      captcha = Request.Form["Captcha"];
                if (!string.IsNullOrEmpty(captcha))
                {
                    if (!Captcha.CheckCaptcha(Request.Form["CaptchaName"], captcha))
                    {
                        throw new Exception();
                    }
                }

                long       mobile   = long.Parse(Request.Form["Mobile"]);
                int        timespan = SMSCaptchaSection.GetSection().TimeSpan;
                MobileHash hash     = MobileHash.Create(ds, mobile, type, timespan);
                if (hash == null)
                {
                    throw new Exception();
                }

                string     md5 = string.Concat(Request.UserHostAddress, "\r\n", Request.UserAgent).MD5();
                StringHash sh  = StringHash.Create(ds, md5, StringHash.SmsHash, timespan);
                if (sh == null)
                {
                    throw new Exception();
                }

                SmsTemplate temp = SmsTemplate.GetByName(ds, SmsTemplate.Register);
                if (temp.Type == SmsTemplateType.Template)
                {
                    SendTemplateImpl(name, mobile, temp.Content, ds, hash.Hash);
                }
                else
                {
                    SendImpl(name, mobile, temp.Content, ds, hash.Hash);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #3
0
        public void SendSms(string name)
        {
            try
            {
                PassportSection section = PassportSection.GetSection();
                if (!section.VerifyMobile)
                {
                    throw new Exception();
                }

                long         mobile   = long.Parse(Request.Form["Mobile"]);
                int          timespan = SMSCaptchaSection.GetSection().TimeSpan;
                V.MobileHash hash     = V.MobileHash.Create(DataSource, mobile, V.MobileHash.Password, timespan);
                if (hash == null)
                {
                    throw new Exception();
                }

                string       md5 = string.Concat(ClientIp, "\r\n", Request.UserAgent).MD5();
                V.StringHash sh  = V.StringHash.Create(DataSource, md5, V.StringHash.SmsHash, timespan);
                if (sh == null)
                {
                    throw new Exception();
                }

                S.SmsTemplate temp = S.SmsTemplate.GetByName(DataSource, S.SmsTemplate.Register);
                if (temp.Type == S.SmsTemplateType.Template)
                {
                    SendTemplateImpl(name, mobile, temp.Content, hash.Hash);
                }
                else
                {
                    SendImpl(name, mobile, temp.Content, hash.Hash);
                }
                SetResult(true);
            }
            catch (Exception)
            {
                SetResult(false);
            }
        }