Example #1
0
        public static MobileHash Create(DataSource ds, long mobile, int type, int timespan)
        {
            MobileHash hash = Db <MobileHash> .Query(ds)
                              .Select()
                              .Where(W("Type", type) & W("Mobile", mobile))
                              .First <MobileHash>();

            if (hash != null)
            {
                if (hash.CreationDate.AddSeconds(timespan) > DateTime.Now)
                {
                    return(null);
                }
                hash.Hash         = RndHash();
                hash.CreationDate = DateTime.Now;
                if (hash.Update(ds) == DataStatus.Success)
                {
                    return(hash);
                }
            }
            else
            {
                hash = new MobileHash()
                {
                    Mobile = mobile, Type = type, Hash = RndHash(), CreationDate = DateTime.Now
                };
                if (hash.Insert(ds) == DataStatus.Success)
                {
                    return(hash);
                }
            }
            return(null);
        }
Example #2
0
        public static bool Equals(DataSource ds, long mobile, int type, string hash)
        {
            if (!mobile.IsMobile() || string.IsNullOrEmpty(hash))
            {
                return(false);
            }
            MobileHash mh = ExecuteSingleRow <MobileHash>(ds, P("Type", type) & P("Mobile", mobile));

            if (mh == null)
            {
                return(false);
            }
            if (!string.Equals(mh.Hash, hash, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            SMSCaptchaSection section = SMSCaptchaSection.GetSection();

            if (section.Expiration > 0 && mh.CreationDate.AddSeconds(section.Expiration) < DateTime.Now)
            {
                return(false);
            }
            mh.Hash         = string.Empty;
            mh.CreationDate = (DateTime)Types.GetDefaultValue(TType <DateTime> .Type);
            mh.Update(ds);
            return(true);
        }
Example #3
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);
            }
        }
Example #4
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);
            }
        }