Exemplo n.º 1
0
        private SessionListReply FormatSessionListReply(List <AuthSession> sessions)
        {
            SessionListReply reply = new SessionListReply();

            foreach (AuthSession session in sessions)
            {
                Session replySession = new Session
                {
                    Id           = session.Id.ToString(),
                    LastActive   = NodaTime.Serialization.Protobuf.NodaExtensions.ToTimestamp(session.LastUsedTime),
                    LastLocation = "TODO",
                    Name         = session.Name,
                    SignedIn     = NodaTime.Serialization.Protobuf.NodaExtensions.ToTimestamp(session.CreationTime),
                };

                Instant?expiredTime = session.ExpiredTime;
                if (expiredTime != null)
                {
                    replySession.InvalidatedAt = NodaTime.Serialization.Protobuf.NodaExtensions.ToTimestamp((Instant)expiredTime);
                }

                reply.Sessions.Add(replySession);
            }

            return(reply);
        }
Exemplo n.º 2
0
        private SessionListReply FormatSessionListReply(List <AuthSession> sessions, ServerCallContext context)
        {
            SessionListReply reply           = new SessionListReply();
            Guid             currentCookieId = _sessionManager.GetCurrentSessionId(context.GetHttpContext().User);

            foreach (AuthSession session in sessions)
            {
                string         deviceName = "Unknown";
                DeviceTypeEnum deviceType = DeviceTypeEnum.Unknown;

                if (session.DeviceInfo != null)
                {
                    if (!String.IsNullOrEmpty(session.DeviceInfo.Browser))
                    {
                        deviceName = session.DeviceInfo.Browser;
                        if (!String.IsNullOrEmpty(session.DeviceInfo.Model))
                        {
                            deviceName = deviceName + " on " + session.DeviceInfo.Model;
                        }
                        else if (!String.IsNullOrEmpty(session.DeviceInfo.OperatingSystem))
                        {
                            deviceName = deviceName + " on " + session.DeviceInfo.OperatingSystem;
                        }
                    }

                    switch (session.DeviceInfo.DeviceType)
                    {
                    case DeviceInformation.DeviceTypeEnum.Desktop:
                        deviceType = DeviceTypeEnum.Desktop;
                        break;

                    case DeviceInformation.DeviceTypeEnum.Smartphone:
                        deviceType = DeviceTypeEnum.Smartphone;
                        break;

                    case DeviceInformation.DeviceTypeEnum.Tablet:
                        deviceType = DeviceTypeEnum.Tablet;
                        break;
                    }
                }

                Session replySession = new Session
                {
                    Id               = session.Id.ToString(),
                    LastActive       = NodaTime.Serialization.Protobuf.NodaExtensions.ToTimestamp(session.LastUsedTime),
                    SignedIn         = NodaTime.Serialization.Protobuf.NodaExtensions.ToTimestamp(session.CreationTime),
                    Name             = deviceName,
                    IsCurrentSession = (currentCookieId == session.Id),
                    DeviceType       = deviceType
                };

                foreach (AuthSessionIp sessionIp in session.SessionIps)
                {
                    IPAddress ipAddress = sessionIp.IpAddress;
                    if (ipAddress.IsIPv4MappedToIPv6)
                    {
                        ipAddress = ipAddress.MapToIPv4();
                    }

                    Session.Types.LocationReply locationReply = new Session.Types.LocationReply
                    {
                        IpAddress = ipAddress.ToString(),
                        Country   = sessionIp.Country,
                        City      = sessionIp.City,
                    };
                    replySession.Locations.Add(locationReply);
                }

                Instant?expiredTime = session.ExpiredTime;
                if (expiredTime != null)
                {
                    replySession.InvalidatedAt = NodaTime.Serialization.Protobuf.NodaExtensions.ToTimestamp((Instant)expiredTime);
                }

                reply.Sessions.Add(replySession);
            }

            return(reply);
        }