Beispiel #1
0
        public static BranchSession Create(string ipAddress, string userAgent, BranchIdentity branchIdentity, bool rememberMe)
        {
            var modernAgent = new ModernAgent(userAgent);

            var session = new BranchSession
            {
                Revoked        = false,
                Ip             = ipAddress,
                Identifier     = Guid.NewGuid(),
                Browser        = modernAgent.Browser(),
                Platform       = modernAgent.OperatingSystem(),
                UserAgent      = userAgent,
                BranchIdentity = branchIdentity,
                ExpiresAt      = rememberMe ? DateTime.UtcNow.AddYears(1) : DateTime.UtcNow.AddDays(1)
            };

            if (ipAddress == "127.0.0.1")
            {
                session.FriendlyLocation = "Unknown Location - Developer Session - Running on Local Machine";
                session.GpsLocation      = String.Format("{0},{1}", 0, 0);
                return(session);
            }

            var g = IpGeolocation.Geolocate(ipAddress);

            if (g.Latitude <= -1336)
            {
                session.FriendlyLocation = "Unknown Location";
                session.GpsLocation      = String.Format("{0},{1}", 0, 0);
                return(session);
            }

            var gg = new Geocoding.Google.GoogleGeocoder().ReverseGeocode(g.Latitude, g.Longitude).ToList();

            if (gg.Any())
            {
                var ggg = gg.First();
                session.FriendlyLocation = ggg.FormattedAddress;
                session.GpsLocation      = String.Format("{0},{1}", ggg.Coordinates.Latitude, ggg.Coordinates.Longitude);
            }
            else
            {
                session.FriendlyLocation = "Unknown Location";
                session.GpsLocation      = String.Format("{0},{1}", 0, 0);
            }

            return(session);
        }
Beispiel #2
0
        public static BranchSession Create(string ipAddress, string userAgent, BranchIdentity branchIdentity, bool rememberMe)
        {
            var modernAgent = new ModernAgent(userAgent);

            var session = new BranchSession
            {
                Revoked = false,
                Ip = ipAddress,
                Identifier = Guid.NewGuid(),
                Browser = modernAgent.Browser(),
                Platform = modernAgent.OperatingSystem(),
                UserAgent = userAgent,
                BranchIdentity = branchIdentity,
                ExpiresAt = rememberMe ? DateTime.UtcNow.AddYears(1) : DateTime.UtcNow.AddDays(1)
            };

            if (ipAddress == "127.0.0.1")
            {
                session.FriendlyLocation = "Unknown Location - Developer Session - Running on Local Machine";
                session.GpsLocation = String.Format("{0},{1}", 0, 0);
                return session;
            }

            var g = IpGeolocation.Geolocate(ipAddress);
            if (g.Latitude <= -1336)
            {
                session.FriendlyLocation = "Unknown Location";
                session.GpsLocation = String.Format("{0},{1}", 0, 0);
                return session;
            }

            var gg = new Geocoding.Google.GoogleGeocoder().ReverseGeocode(g.Latitude, g.Longitude).ToList();
            if (gg.Any())
            {
                var ggg = gg.First();
                session.FriendlyLocation = ggg.FormattedAddress;
                session.GpsLocation = String.Format("{0},{1}", ggg.Coordinates.Latitude, ggg.Coordinates.Longitude);
            }
            else
            {
                session.FriendlyLocation = "Unknown Location";
                session.GpsLocation = String.Format("{0},{1}", 0, 0);
            }

            return session;
        }