protected void Page_Load(object sender, EventArgs e) { if (SecurityContext.IsAuthenticated && User.ID != SecurityContext.CurrentAccount.ID) { Response.Redirect(GetRefererURL()); return; } if (!CoreContext.Configuration.YourDocs) { _communitations.Controls.Add(LoadControl(AuthCommunications.Location)); } AjaxPro.Utility.RegisterTypeForAjax(GetType()); Page.RegisterBodyScripts(ResolveUrl("~/usercontrols/Management/SmsControls/js/confirmmobile.js")); Page.RegisterStyleControl(VirtualPathUtility.ToAbsolute("~/usercontrols/management/SmsControls/css/confirmmobile.less")); Context.Session["SmsAuthData"] = User.ID; if (string.IsNullOrEmpty(User.MobilePhone)) Activation = true; if (!Activation) { try { SmsManager.PutAuthCode(User, false); } catch (Exception) { Activation = true; } } if (Activation) { var ipGeolocationInfo = new GeolocationHelper("db").GetIPGeolocationFromHttpContext(); if (ipGeolocationInfo != null) Country = ipGeolocationInfo.Key; var clientScriptReference = new ClientScriptReference(); clientScriptReference.Includes.Add(typeof(CountriesResources)); Page.RegisterBodyScripts(clientScriptReference); Page.RegisterBodyScripts(ResolveUrl("~/js/asc/plugins/countries.js")); Page.RegisterBodyScripts(ResolveUrl("~/js/asc/plugins/phonecontroller.js")); Page.RegisterStyleControl(VirtualPathUtility.ToAbsolute("~/skins/default/phonecontroller.css")); } }
public void GetIPGeolocationTest() { var helper = new GeolocationHelper("db"); var info = helper.GetIPGeolocation("62.213.10.13"); Assert.AreEqual("Nizhny Novgorod", info.City); Assert.AreEqual("062.213.011.127", info.IPEnd); Assert.AreEqual("062.213.008.240", info.IPStart); Assert.AreEqual("RU", info.Key); Assert.AreEqual("Europe/Moscow", info.TimezoneName); Assert.AreEqual(4d, info.TimezoneOffset); info = helper.GetIPGeolocation(""); Assert.AreEqual(IPGeolocationInfo.Default.City, info.City); Assert.AreEqual(IPGeolocationInfo.Default.IPEnd, info.IPEnd); Assert.AreEqual(IPGeolocationInfo.Default.IPStart, info.IPStart); Assert.AreEqual(IPGeolocationInfo.Default.Key, info.Key); Assert.AreEqual(IPGeolocationInfo.Default.TimezoneName, info.TimezoneName); Assert.AreEqual(IPGeolocationInfo.Default.TimezoneOffset, info.TimezoneOffset); }
protected void SetLanguage(bool checkIp = true) { if (Request.QueryString.Count == 0) { var ipGeolocationInfo = new GeolocationHelper("teamlabsite").GetIPGeolocationFromHttpContext(); if (checkIp && ipGeolocationInfo != null && !string.IsNullOrEmpty(ipGeolocationInfo.Key)) { var cultureInfo = SetupInfo.EnabledCultures.Find(c => String.Equals(c.TwoLetterISOLanguageName, ipGeolocationInfo.Key, StringComparison.InvariantCultureIgnoreCase)); if (cultureInfo != null) { Response.Redirect(Request.Path + "?lang=" + cultureInfo.TwoLetterISOLanguageName, true); } } } else { var lang = Request["lang"]; if (!string.IsNullOrEmpty(lang)) { var cultureInfo = SetupInfo.EnabledCultures.Find(c => String.Equals(c.TwoLetterISOLanguageName, lang, StringComparison.InvariantCultureIgnoreCase)); if (cultureInfo != null) { Thread.CurrentThread.CurrentUICulture = cultureInfo; } } } }
protected void SetLanguage(bool checkIp = true, bool abTesting = false) { var abTestingQuery = string.Empty; if (abTesting) abTesting = AbTestingQuery(out abTestingQuery); if (Request.QueryString.Count == 0) { var ipGeolocationInfo = new GeolocationHelper("teamlabsite").GetIPGeolocationFromHttpContext(); if (checkIp && ipGeolocationInfo != null && !string.IsNullOrEmpty(ipGeolocationInfo.Key)) { var cultureInfo = SetupInfo.EnabledCultures.Find(c => String.Equals(c.TwoLetterISOLanguageName, ipGeolocationInfo.Key, StringComparison.InvariantCultureIgnoreCase)); if (cultureInfo != null) { var redirectUrl = String.Format("/{0}/{1}", cultureInfo.TwoLetterISOLanguageName, Request.Path); if (redirectUrl.EndsWith("auth.aspx", StringComparison.InvariantCulture)) redirectUrl = redirectUrl.Remove(redirectUrl.IndexOf("auth.aspx", StringComparison.Ordinal)); if (abTesting) redirectUrl += (redirectUrl.Contains("?") ? "&" : "?") + abTestingQuery; Response.Redirect(redirectUrl, true); } } } else { var lang = Request["lang"]; if (!string.IsNullOrEmpty(lang)) { lang = lang.Split(',')[0]; var cultureInfo = SetupInfo.EnabledCultures.Find(c => String.Equals(c.TwoLetterISOLanguageName, lang, StringComparison.InvariantCultureIgnoreCase)); if (cultureInfo != null) { Thread.CurrentThread.CurrentUICulture = cultureInfo; } else { Log.WarnFormat("Lang {0} not supported", lang); } } } if (abTesting) { var redirectUrl = Request.Path; redirectUrl += (redirectUrl.Contains("?") ? "&" : "?") + abTestingQuery; Response.Redirect(redirectUrl, true); } }