コード例 #1
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);
        }
コード例 #2
0
        private static string RndHash()
        {
            SMSCaptchaSection section = SMSCaptchaSection.GetSection();
            StringBuilder     sb      = new StringBuilder(section.DefaultCount);
            Random            rnd     = new Random();

            for (int i = 0; i < section.DefaultCount; ++i)
            {
                sb.Append(section.Chars[rnd.Next(0, section.DefaultCount)]);
            }
            return(sb.ToString());
        }
コード例 #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);
            }
        }
コード例 #4
0
        public void Cb(string type)
        {
            string target = Request.QueryString["target"];

            if (string.IsNullOrEmpty(target))
            {
                target = GetUrl("/");
            }
            OAuth2Provider provider = GetProvider(type);

            if (provider != null)
            {
                OAuth2TokenAccess token = provider.Access() as OAuth2TokenAccess;
                M.OAuth2Member    user  = provider.GetUserInfo(token);
                if (!string.IsNullOrEmpty(user.UserId))
                {
                    M.Member      member;
                    M.LoginStatus status = M.OAuth2Member.Login(DataSource, type.ToLower(), user.UserId, ClientIp, out member);
                    if (status == M.LoginStatus.Success)
                    {
                        PassportAuthentication.SetAuthCookie(true, false, member);
                        OnLogined(member.Id);
                        Refresh(target);
                    }
                    else
                    {
                        if (status == M.LoginStatus.NeedBind)
                        {
                            this["Oauth2Type"]   = user.Type;
                            this["Oauth2UserId"] = user.UserId;
                            this["Target"]       = target;
                            this["Sms"]          = SMSCaptchaSection.GetSection();
                            Render("oauth2.html");
                        }
                        else
                        {
                            Redirect(GetUrl("/login"));
                        }
                    }
                }
                else
                {
                    Redirect(GetUrl("/login"));
                }
            }
            else
            {
                Redirect(GetUrl("/login"));
            }
        }
コード例 #5
0
        public void Reg()
        {
            string target = Request.QueryString["target"];

            if (string.IsNullOrEmpty(target))
            {
                if (Request.UrlReferrer != null)
                {
                    target = Request.UrlReferrer.ToString();
                }
            }
            this["Target"] = target;
            this["Config"] = PassportSection.GetSection();
            this["Sms"]    = SMSCaptchaSection.GetSection();
            Render("reg.html");
        }
コード例 #6
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);
            }
        }
コード例 #7
0
 public void UpdatePhone()
 {
     this["Sms"]    = SMSCaptchaSection.GetSection();
     this["Member"] = M.MemberInfo.GetBySecurity(DataSource, User.Identity.Id);
     Render("update_phone.html");
 }
コード例 #8
0
        public void System(string type)
        {
            if (CheckRight())
            {
                if (CheckPost(string.Concat("system_", type), new Action(() =>
                {
                    switch (type)
                    {
                    case "config":
                        this["Config"] = new
                        {
                            Theme = Application.Settings.Theme,
                            UrlMode = Application.Settings.UrlMode.ToString(),
                            Management = Application.Settings.Management,
                            Themes = Application.Settings.GetThemes(),
                            WapDomain = Application.Settings.WapDomain,
                            SubDomain = Application.Settings.SubDomain,
                            DataProvider = Application.Settings.DataProvider,
                            CacheMode = Application.Settings.CacheMode,
                            CacheProvider = Application.Settings.CacheProvider,
                            ResourcesUrl = Application.Settings.ResourcesUrl,
                            PassportUrl = Application.Settings.PassportUrl
                        };
                        this["Conns"] = WebConfigurationManager.ConnectionStrings;
                        break;

                    case "passport":
                        this["Config"] = PassportSection.GetSection();
                        this["Conns"] = WebConfigurationManager.ConnectionStrings;
                        break;

                    case "captcha":
                        this["Config"] = CaptchaSection.GetSection();
                        break;

                    case "smscaptcha":
                        this["Config"] = SMSCaptchaSection.GetSection();
                        break;

                    case "filesystem":
                        this["Config"] = FileSystemSection.GetSection();
                        break;

                    case "email":
                        this["Config"] = (SmtpSection)WebConfigurationManager.GetSection("system.net/mailSettings/smtp");
                        break;

                    case "friendlink":
                        this["Config"] = FriendLinkSection.GetSection();
                        break;

                    case "robots":
                        {
                            string content = string.Empty;
                            try
                            {
                                string file = Server.MapPath("~/robots.txt");
                                content = Encoding.UTF8.GetString(File.ReadAllBytes(file));
                            }
                            catch (Exception) { }
                            this["Robots"] = content;
                        }
                        break;

                    case "sitemap":
                        break;
                    }
                })))
                {
                    switch (type)
                    {
                    case "site":
                    {
                        int           i  = 0;
                        StringBuilder sb = new StringBuilder();
                        foreach (string key in Request.Form.Keys)
                        {
                            if (i++ > 0)
                            {
                                sb.Append(',');
                            }
                            sb.Append(string.Concat("\"", key, "\"=\"", HttpUtility.HtmlEncode(Request.Form[key]), "\""));
                        }
                        try
                        {
                            File.WriteAllText(Server.MapPath(string.Concat(Utility.ConfigDir, "site.config")), string.Concat("$set(Site=array(", sb.ToString(), "))"));
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "config":
                    {
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            SiteSection ss = SiteSection.GetSection(config);
                            ss.Theme = Request.Form["Theme"];
                            try { ss.UrlMode = (SiteUrlMode)int.Parse(Request.Form["UrlMode"]); }
                            catch (Exception) { ss.UrlMode = SiteUrlMode.Rewrite; }
                            ss.Management   = Request.Form["Management"];
                            ss.WapDomain    = Request.Form["WapDomain"];
                            ss.SubDomain    = Request.Form["SubDomain"];
                            ss.DataProvider = Request.Form["DataProvider"];
                            try { ss.CacheMode = (CacheMode)int.Parse(Request.Form["CacheMode"]); }
                            catch (Exception) { ss.CacheMode = CacheMode.Application; }
                            ss.CacheProvider  = Request.Form["CacheProvider"];
                            ss.ResourcesUrl   = Request.Form["ResourcesUrl"];
                            ss.PassportUrl    = Request.Form["PassportUrl"];
                            ss.WapPassportUrl = Request.Form["WapPassportUrl"];
                            config.Save();
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "passport":
                    {
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            PassportSection section = PassportSection.GetSection(config);
                            section.CookieName   = Request.Form["CookieName"];
                            section.CookieDomain = Request.Form["CookieDomain"];
                            section.CookieIV     = Request.Form["CookieIV"];
                            section.CookieKey    = Request.Form["CookieKey"];
                            section.MaxInvalidPasswordAttempts           = GetInt32Value(Request.Form["MaxInvalidPasswordAttempts"], Utility.PassportMaxInvalidPasswordAttempts);
                            section.PasswordAnswerAttemptLockoutDuration = GetInt32Value(Request.Form["PasswordAnswerAttemptLockoutDuration"], Utility.PassportPasswordAnswerAttemptLockoutDuration);
                            try { section.Level = (PassportLevel)int.Parse(Request.Form["Level"]); }
                            catch (Exception) { section.Level = PassportLevel.Low; }
                            section.VerifyMail          = GetBooleanValue(Request.Form["VerifyMail"]);
                            section.VerifyMobile        = GetBooleanValue(Request.Form["VerifyMobile"]);
                            section.LoginWithCaptcha    = GetBooleanValue(Request.Form["LoginWithCaptcha"]);
                            section.RegisterWithCaptcha = GetBooleanValue(Request.Form["RegisterWithCaptcha"]);
                            section.DefaultApproved     = GetBooleanValue(Request.Form["DefaultApproved"]);
                            section.DataProvider        = Request.Form["DataProvider"];
                            config.Save();
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "cache":
                        CacheProvider.Current.Clear();
                        SetResult(() =>
                        {
                            WriteLog("CLEAR CACHE");
                        });
                        break;

                    case "captcha":
                    {
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            CaptchaSection section = CaptchaSection.GetSection(config);
                            section.Chars         = Request.Form["Chars"];
                            section.CookiePrefix  = Request.Form["CookiePrefix"];
                            section.CookieDomain  = Request.Form["CookieDomain"];
                            section.DefaultWidth  = GetInt32Value(Request.Form["DefaultWidth"], Utility.CaptchaDefaultWidth);
                            section.DefaultHeight = GetInt32Value(Request.Form["DefaultHeight"], Utility.CaptchaDefaultHeight);
                            section.DefaultCount  = GetInt32Value(Request.Form["DefaultCount"], Utility.CaptchaDefaultCount);
                            section.Expiration    = GetInt32Value(Request.Form["Expiration"], Utility.CaptchaExpiration);
                            config.Save();
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "smscaptcha":
                    {
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            SMSCaptchaSection section = SMSCaptchaSection.GetSection(config);
                            section.Chars        = Request.Form["Chars"];
                            section.DefaultCount = GetInt32Value(Request.Form["DefaultCount"], Utility.SMSCaptchaDefaultCount);
                            section.TimeSpan     = GetInt32Value(Request.Form["TimeSpan"], Utility.SMSCaptchaTimeSpan);
                            section.Expiration   = GetInt32Value(Request.Form["Expiration"], Utility.SMSCaptchaExpiration);
                            config.Save();
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "filesystem":
                    {
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            FileSystemSection section = FileSystemSection.GetSection(config);
                            section.Enable = Types.GetBooleanFromString(Request.Form["Enable"]);
                            section.Path   = Request.Form["Path"];
                            section.Url    = Request.Form["Url"];
                            try { section.Mark = (ImageMarkType)int.Parse(Request.Form["Mark"]); }
                            catch (Exception) { section.Mark = ImageMarkType.None; }
                            section.Text   = Request.Form["Text"];
                            section.Region = (ImageMarkRegion)int.Parse(Request.Form["Region"]);
                            try { section.Width = int.Parse(Request.Form["Width"]); }
                            catch (Exception) { section.Width = 0; }
                            try { section.Height = int.Parse(Request.Form["Height"]); }
                            catch (Exception) { section.Height = 0; }
                            config.Save();
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "email":
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            SmtpSection section = (SmtpSection)config.GetSection("system.net/mailSettings/smtp");
                            section.From              = Request.Form["UserName"];
                            section.Network.Host      = Request.Form["Host"];
                            section.Network.Port      = GetInt32Value(Request.Form["Port"], 25);
                            section.Network.UserName  = Request.Form["UserName"];
                            section.Network.Password  = Request.Form["Password"];
                            section.Network.EnableSsl = GetBooleanValue(Request.Form["EnableSsl"]);
                            config.Save();
                            SetResult(() =>
                            {
                                WritePostLog("MOD");
                            });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                        break;

                    case "friendlink":
                    {
                        try
                        {
                            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
                            FriendLinkSection section = FriendLinkSection.GetSection(config);
                            section.Enable   = Types.GetBooleanFromString(Request.Form["Enable"]);
                            section.Approved = Types.GetBooleanFromString(Request.Form["Approved"]);
                            try { section.Mode = (FriendLinkMode)int.Parse(Request.Form["Mode"]); }
                            catch (Exception) { section.Mode = FriendLinkMode.Text; }
                            config.Save();
                            SetResult(() =>
                                {
                                    WritePostLog("MOD");
                                });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                    }
                    break;

                    case "robots":
                        try
                        {
                            string file = Server.MapPath("~/robots.txt");
                            File.WriteAllBytes(file, Encoding.UTF8.GetBytes(Request.Form["Robots"]));
                            SetResult(() =>
                            {
                                WritePostLog("SUB");
                            });
                        }
                        catch (Exception ex)
                        {
                            SetResult(false, ex.Message);
                        }
                        break;

                    case "sitemap":
                        break;
                    }
                }
            }
        }
コード例 #9
0
 public void Index()
 {
     this["Sms"] = SMSCaptchaSection.GetSection();
     Render("password.html");
 }