コード例 #1
0
        private AndroidPremiumCustomer GetCustomer(string uniqueID, string applicationName, string ipAddress, string msisdn, string referrer)
        {
            AndroidPremiumCustomer customer = AndroidPremiumCustomer.CreateManager().Load(uniqueID);

            if (customer != null)
            {
                return(customer);
            }

            AndroidPremiumAplication app = AndroidPremiumAplication.CreateManager().Load(applicationName);

            if (app == null)
            {
                app = new AndroidPremiumAplication(-1, applicationName, DateTime.Now, DateTime.Now);
                app.Insert();
            }

            if (ipAddress == "::1")
            {
                ipAddress = "62.4.59.218";
            }

            IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();
            IPCountryMap         countryMap  = ipcmManager.Load(ipAddress);

            if (countryMap == null || countryMap.Country == null)
            {
                Log.Fatal("Could not load Country by ID:" + ipAddress);
                return(null);
            }

            customer = new AndroidPremiumCustomer(-1,
                                                  uniqueID,
                                                  app,
                                                  countryMap.Country,
                                                  ipAddress,
                                                  msisdn,
                                                  referrer,
                                                  DateTime.Now, DateTime.Now);
            customer.Insert();

            return(customer);
        }
コード例 #2
0
        protected virtual void InitializeSession(HttpContext httpContext)
        {
            string sessionID   = httpContext.Session.SessionID;
            Guid   sessionGuid = Guid.Empty;

            if (!Guid.TryParseExact(sessionID, "N", out sessionGuid))
            {
                // TODO: log4net
                //if (Log.IsWarnEnabled)
                //  Log.Warn(new LogMessageBuilder(
                //    new LogErrorCode("paywall.web.core", "paywallhttpcontext", "initializesession"),
                //      "Invalid session ID", sessionGuid));

                throw new ArgumentException("MobiContext: Could not parse Session guid");
            }

            IUserSessionManager usManager = UserSession.CreateManager();
            UserSession         session   = usManager.Load(sessionGuid);

            if (session != null && session.IPAddress != httpContext.Request.UserHostAddress)
            {
                // TODO: Session hijack.. log
            }

            if (session == null)
            {
                IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();

                // TODO: Remove this in production
                string ipAddress = !httpContext.Request.UserHostAddress.Equals("::1") && !httpContext.Request.UserHostAddress.StartsWith("192.") ?
                                   httpContext.Request.UserHostAddress :
                                   "78.155.61.246";

                IPCountryMap countryMap = ipcmManager.Load(ipAddress);
                Language     language   = countryMap.Country.Language != null ? countryMap.Country.Language : Language.CreateManager().Load("EN", LanguageIdentifier.TwoLetterIsoCode);

                session = new UserSession(-1,
                                          sessionGuid,
                                          StatisticsApplication.GetDefaultUserSessionType(),
                                          null,     // service
                                          this.Runtime.ApplicationData,
                                          null,     // domain,
                                          null,     // user,
                                          countryMap.Country,
                                          language, // language
                                          null,     // mobileOperator
                                          null,     // trackingID,
                                          httpContext.Request.UserHostAddress,
                                          httpContext.Request.UserAgent,
                                          httpContext.Request.Url.ToString().Replace(" ", string.Empty),
                                          httpContext.Request.UrlReferrer != null ? httpContext.Request.UrlReferrer.ToString() : null,
                                          false,
                                          DateTime.Now.AddMinutes(20),
                                          DateTime.Now, DateTime.Now);

                session.Insert();

                //INFO: DO NOT DO ANYTHING WITH THIS LINE BELOW!!!
                httpContext.Session["someValue"] = "bla";
            }

            this._session = new StatisticsUserSession(session);
        }
コード例 #3
0
ファイル: MobiContext.cs プロジェクト: aco228/MobiChat
        protected virtual void InitializeSession(HttpContext httpContext)
        {
            string sessionID   = httpContext.Session.SessionID;
            Guid   sessionGuid = Guid.Empty;

            if (!Guid.TryParseExact(sessionID, "N", out sessionGuid))
            {
                Log.Error("Invalid session ID" + sessionGuid);
            }

            IUserSessionManager usManager = UserSession.CreateManager();
            UserSession         session   = usManager.Load(this.Service.ServiceData, sessionGuid);

            if (session != null && session.IPAddress != httpContext.Request.UserHostAddress)
            {
                Log.Error("Session hijack!");
            }

            if (session == null)
            {
                // TODO: Remove this in production
                string ipAddress = !httpContext.Request.UserHostAddress.Equals("::1") && !httpContext.Request.UserHostAddress.StartsWith("192.") ?
                                   httpContext.Request.UserHostAddress :
                                   "78.155.61.246";

                IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();
                IPCountryMap         countryMap  = ipcmManager.Load(ipAddress);

                Language language = countryMap.Country.Language != null ? countryMap.Country.Language : Language.CreateManager().Load("EN", LanguageIdentifier.TwoLetterIsoCode);

                session = new UserSession(-1,
                                          sessionGuid,
                                          this.Service.ServiceData.UserSessionType,
                                          this.Service.ServiceData,
                                          null,
                                          this.Domain,
                                          null,
                                          countryMap.Country,
                                          language,
                                          null,
                                          null,
                                          httpContext.Request.UserHostAddress,
                                          httpContext.Request.UserAgent,
                                          httpContext.Request.Url.ToString(),
                                          httpContext.Request.UrlReferrer != null ? httpContext.Request.UrlReferrer.ToString() : null,
                                          false,
                                          DateTime.Now.AddMinutes(20),
                                          DateTime.Now, DateTime.Now);

                // TODO: Make this dynamic
                if (!session.EntranceUrl.Contains("/thumbnail") &&
                    !session.EntranceUrl.EndsWith("/logo"))
                {
                    session.Insert();
                }

                //INFO: DO NOT DO ANYTHING WITH THIS LINE BELOW!!!
                httpContext.Session["someValue"] = "bla";
            }

            this._session = new WebUserSession(session);
        }
コード例 #4
0
        // SUMMARY: Register new device
        public ActionResult Register()
        {
            Log.Info("Entrance:: Into for IP:" + Request.UserHostAddress + "; url= " + Request.RawUrl);

            string applicationID    = Request["applicationID"] != null ? Request["applicationID"].ToString() : "";
            string androidUniqueID  = Request["androidUniqueID"] != null ? Request["androidUniqueID"].ToString() : "";
            string tokenID          = Request["tokenID"] != null ? Request["tokenID"].ToString() : "";
            string osVersion        = Request["osVersion"] != null ? Request["osVersion"].ToString() : "";
            string versionSdk       = Request["versionSdk"] != null ? Request["versionSdk"].ToString() : "";
            string device           = Request["device"] != null ? Request["device"].ToString() : "";
            string model            = Request["model"] != null ? Request["model"].ToString() : "";
            string product          = Request["product"] != null ? Request["product"].ToString() : "";
            string company          = Request["company"] != null ? Request["company"].ToString() : "";
            string msisdn           = Request["msisdn"] != null ? Request["msisdn"].ToString() : "";
            string referrer         = Request["referrer"] != null ? Request["referrer"].ToString() : "";
            string hasSmsPermission = Request["hasSmsPermission"] != null ? Request["hasSmsPermission"].ToString() : "";
            string ipAddress        = Request.UserHostAddress;

            Log.Debug("Entrance::: applicationID=" + applicationID + Environment.NewLine
                      + "androidUniqueID=" + androidUniqueID + Environment.NewLine
                      + "tokenID=" + tokenID + Environment.NewLine
                      + "osVersion=" + osVersion + Environment.NewLine
                      + "versionSdk=" + versionSdk + Environment.NewLine
                      + "device=" + device + Environment.NewLine
                      + "model=" + model + Environment.NewLine
                      + "product=" + product + Environment.NewLine
                      + "company=" + company + Environment.NewLine
                      + "msisdn=" + msisdn + Environment.NewLine
                      + "referrer=" + referrer + Environment.NewLine
                      + "hasSmsPermission=" + hasSmsPermission + Environment.NewLine
                      + "ipAddress=" + ipAddress + Environment.NewLine);

            if (ipAddress == "::1")
            {
                ipAddress = "37.0.70.126";
            }

            if (string.IsNullOrEmpty(applicationID) || string.IsNullOrEmpty(osVersion) || string.IsNullOrEmpty(device) || string.IsNullOrEmpty(model))
            {
                return(this.Json(new { status = false, message = "osVersion, device od model are empty" }, JsonRequestBehavior.AllowGet));
            }

            int _applicationID = -1;

            if (!Int32.TryParse(applicationID, out _applicationID))
            {
                return(this.Json(new { status = false, message = "ApplicationID could not be parsed" }));
            }

            AndroidDistribution androidDistribution = AndroidDistribution.CreateManager().Load(_applicationID);

            if (androidDistribution == null)
            {
                return(this.Json(new { status = false, message = "Distribution could not be loaded with id=" + _applicationID }));
            }

            AndroidClientSession session = null;

            session = AndroidClientSession.CreateManager().Load(androidDistribution, androidUniqueID);

            try
            {
                IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();
                IPCountryMap         countryMap  = ipcmManager.Load(ipAddress);

                if (countryMap == null || countryMap.Country == null)
                {
                    Log.Fatal("Could not load Country by ID:" + ipAddress);
                    return(this.Json(new { status = false, message = "Could not load country" }));
                }

                if (session == null)
                {
                    session = new AndroidClientSession(-1,
                                                       androidDistribution, androidDistribution.AndroidDistributionGroup,
                                                       androidUniqueID, tokenID, countryMap.Country, msisdn, osVersion, versionSdk, device, company, model, product,
                                                       this.GetFingerprint(), referrer,
                                                       (!string.IsNullOrEmpty(hasSmsPermission) && hasSmsPermission.Equals("true")), // hasSmsPermissions
                                                       DateTime.Now, DateTime.Now, DateTime.Now);
                    session.Insert();

                    Log.Info("Entrance:: Session created with ID:" + session.ID);
                    AndroidClientLog.Log(session.ID, "CREATED", "Session created", false);
                }
                else
                {
                    if (!string.IsNullOrEmpty(tokenID))
                    {
                        session.TokenID = tokenID;
                    }
                    if (!string.IsNullOrEmpty(referrer))
                    {
                        session.Referrer = referrer;
                    }

                    session.Country          = countryMap.Country;
                    session.Msisdn           = msisdn;
                    session.OSVersion        = osVersion;
                    session.VersionSDK       = versionSdk;
                    session.Device           = device;
                    session.Company          = company;
                    session.Model            = model;
                    session.Product          = product;
                    session.HasSmsPermission = hasSmsPermission.Equals("true");
                    session.Update();

                    Log.Info("Entrance:: Session taken with ID:" + session.ID);
                    AndroidClientLog.Log(session.ID, "UPDATED", "Session updated", false);
                }

                this.HttpContext.Session["sid"] = session.ID;
                return(this.Json(new { status = true, sessionID = session.ID }, JsonRequestBehavior.AllowGet));;
            }
            catch (Exception e)
            {
                Log.Fatal("Register:: Fatal", e);
                return(this.Json(new { status = false, message = e.Message }));
            }
        }