Ejemplo n.º 1
0
        public string GetUserByAccountName(Stream stream)
        {
            string       accountName = string.Empty;
            string       passWord    = string.Empty;
            StreamReader sr          = new StreamReader(stream);


            try
            {
                IPInfoModel iPInfo = RequestHelper.RequestInfo();

                string s = sr.ReadToEnd(); s = RestConsoleDemo.BLL.Helper.Base64Helper.DecodeBase64NotEnd(s);
                ResponseHelper.SetHeaderInfo();
                NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
                accountName = nvc["accountName"];
                passWord    = nvc["passWord"];
                string str = UserBill.GetUserByAccountName(accountName, passWord, iPInfo.Address, iPInfo.Port);
                return(str);
                //  sr.Dispose();
                //NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(s);
                //accountName = nvc["accountName"];
                //passWord = nvc["passWord"];
            }
            catch (Exception ex)
            {
                return(RestConsoleDemo.BLL.Helper.ResponseHelper.ResponseMsg("-1", ex.Message, ""));
            }

            //  ResponseHelper.SetHeaderInfo();

            // string str = UserBill.GetUserByAccountName(accountName, passWord);
            //   return str;
        }
Ejemplo n.º 2
0
        public static IPInfoModel RequestInfo()
        {
            OperationContext  context    = OperationContext.Current;
            MessageProperties properties = context.IncomingMessageProperties;
            //获取消息发送的远程终结点IP和端口
            RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            string      Address = endpoint.Address;
            string      Port    = endpoint.Port.ToString();
            IPInfoModel temp    = new IPInfoModel()
            {
                Address = Address,
                Port    = Port
            };

            return(temp);
        }
Ejemplo n.º 3
0
        public async Task CountRedirect(ShortLinkModel shortLink, bool disableTracking)
        {
            var addr = HttpContext.Connection.RemoteIpAddress;

            bool isUnique = true;

            if (IPCache.Contains(addr))
            {
                var guid = IPCache.Get(addr);
                isUnique = !guid.HasValue || guid.Value != shortLink.GUID;
            }

            //Db.ShortLinks.Update(shortLink);

            var ipInfoToken = Configuration.GetSection("secrets")?.GetValue <string>("ipinfotoken");
            var ipInfo      = new IPInfoModel();

            if (!ipInfoToken.IsEmpty())
            {
                try
                {
                    ipInfo = await IPInfo.GetInfo(addr, ipInfoToken);
                }
                catch (Exception e)
                {
                    Logger.LogError("Failed getting IPInfo: ", e);
                }
            }
            else
            {
                Logger.LogWarning("IPInfo could not be collected because no IPInfo API token was provided");
            }

            var access = new AccessModel()
            {
                ShortLinkGUID = shortLink.GUID,
                IsUnique      = isUnique,
                Timestamp     = DateTime.Now,
            };


            if (!disableTracking)
            {
                access.ShortLinkGUID = shortLink.GUID;
                access.City          = ipInfo.City;
                access.Country       = ipInfo.Country;
                access.IsUnique      = isUnique;
                access.Org           = ipInfo.Org;
                access.Postal        = ipInfo.Postal;
                access.Region        = ipInfo.Region;
                access.Timestamp     = DateTime.Now;
                access.Timezone      = ipInfo.Timezone;
                access.UserAgent     = HttpContext.Request.Headers["User-Agent"].ToString();
            }

            DbCache.AddAccess(access);

            if (isUnique)
            {
                IPCache.Push(addr, shortLink.GUID);
            }

            //await Db.SaveChangesAsync();
        }