public ActionResult Test() { var token = Request.QueryString["token"]; //var isLogin = Request.QueryString["continue"]; var sid = WebHelper.UrlDecode(Request.QueryString["sid"]); var strJson = WebHelper.HttpWebRequest("https://bpm.redsun.com.cn:19088/sso.aspx?act=check&type=json&tid=" + token); var result = strJson.ToJObject(); var operators = new Operator { UserId = result["userid"].ToString(), Code = result["userid"].ToString(), Account = result["loginname"].ToString(), UserName = result["name"].ToString(), Password = result["userid"].ToString(), Secretkey = result["userid"].ToString(), CompanyId = result["companyid"].ToString(), DepartmentId = result["departmentid2"].ToString(), IpAddress = Net.Ip, IpAddressName = IpLocation.GetLocation(Net.Ip), //ObjectId = new PermissionBll().GetObjectStr(userEntity.UserId), LogTime = DateTime.Now, Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()) }; OperatorProvider.Provider.AddCurrent(operators); return(Redirect(sid)); }
public async Task <IpLocation> Parse(string ip) { IpLocation parsedIp = new IpLocation(); HttpClient httpClient = HttpClientFactory.Create(); try { if (string.IsNullOrEmpty(ip)) { throw new Exception("IP is null or empty!"); } string requestResult = await httpClient.GetStringAsync($"{this.url}{ip}?access_key={this.accessKey}"); dynamic dynamicParsedIp = JObject.Parse(requestResult); parsedIp.Ip = ip; parsedIp.Continent = dynamicParsedIp.continent_name; parsedIp.Country = dynamicParsedIp.country_name; parsedIp.Region = dynamicParsedIp.region_name; parsedIp.City = dynamicParsedIp.city; } catch (Exception ex) { } return(parsedIp); }
static void PrintIp(IpLocation ipl, string ipAddress) { var result = ipl.GetIpLocation(ipAddress); if (result == null) { Console.WriteLine(ipAddress + " not found"); } else { Console.WriteLine(result); } }
public void AddNew(IpLocation newIpLocation) { Conditions conditions = new Conditions(); conditions.ConditionExpressions.Add(new Condition("StartAt", Operator.EqualTo, newIpLocation.StartAt)); conditions.ConditionExpressions.Add(new Condition("EndAt", Operator.EqualTo, newIpLocation.EndAt)); conditions.Connector = Connector.AND; if (this.dbGateway.getRecord(conditions) == null) { newIpLocation.UpdateTime = (newIpLocation.CreateTime = DateTime.Now); newIpLocation.UpdateStamp = Guid.NewGuid().ToString(); this.dbGateway.AddNew(newIpLocation); } }
public IpLocation GetLocationByIP(long ip) { IpLocation result = null; Conditions conditions = new Conditions(); conditions.Connector = Connector.AND; OrderExpression orderExpression = new OrderExpression("UpdateTime", true); IList <IpLocation> records = this.dbGateway.getRecords(0, 1, conditions, orderExpression, string.Format(" '{0}' between StartIPNum and EndIPNum ", ip)); if (records != null && records.Count > 0) { result = records[0]; } return(result); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: example {ip2location-lite-db5.csv} {dbFileName}"); return; } var ipLocationCsv = args[0]; var ipLocationDb = args[1]; //IpLocation.ImportIpLocationCsv(ipLocationCsv, ipLocationDb); using (var ipl = new IpLocation(ipLocationDb)) { PrintIp(ipl, "8.8.65.8"); PrintIp(ipl, "8.8.4.4"); } }
private static void Write(IpLocation ipLocation) { Console.WriteLine($"ip:{ipLocation.Ip},country:{ipLocation.Country},area:{ipLocation.Area}"); }
public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { var logEntity = new LogEntity { CategoryId = 1, OperateTypeId = ((int)OperationType.Login).ToString(), OperateType = EnumAttribute.GetDescription(OperationType.Login), OperateAccount = username, OperateUserId = username, Module = Config.GetValue("SoftName") }; try { #region 验证码验证 if (autologin == 0) { verifycode = Md5Helper.MD5(verifycode.ToLower(), 16); if (Session["session_verifycode"].IsEmpty() || verifycode != Session["session_verifycode"].ToString()) { throw new Exception("验证码错误,请重新输入"); } } #endregion #region 内部账户验证 var userEntity = new UserBll().CheckLogin(username, password); if (userEntity != null) { var operators = new Operator { UserId = userEntity.UserId, Code = userEntity.EnCode, Account = userEntity.Account, UserName = userEntity.RealName, Password = userEntity.Password, Secretkey = userEntity.Secretkey, CompanyId = userEntity.OrganizeId, DepartmentId = userEntity.DepartmentId, IpAddress = Net.Ip, IpAddressName = IpLocation.GetLocation(Net.Ip), ObjectId = new PermissionBll().GetObjectStr(userEntity.UserId), LogTime = DateTime.Now, Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()) }; var authorizeBll = new AuthorizeBll(); var dataAuthorize = new AuthorizeDataModel { ReadAutorize = authorizeBll.GetDataAuthor(operators), ReadAutorizeUserId = authorizeBll.GetDataAuthorUserId(operators), WriteAutorize = authorizeBll.GetDataAuthor(operators, true), WriteAutorizeUserId = authorizeBll.GetDataAuthorUserId(operators, true) }; operators.DataAuthorize = dataAuthorize; operators.IsSystem = userEntity.Account == "System"; OperatorProvider.Provider.AddCurrent(operators); //写入日志 logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = "登陆成功"; logEntity.WriteLog(); } #endregion #region 第三方账户验证 #endregion return(Success("登陆成功。")); } catch (Exception ex) { WebHelper.RemoveCookie("tony_autologin"); logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = ex.Message; logEntity.WriteLog(); return(Error(ex.Message)); } }
public static void UpdateLocation(IpLocation location) { IPLocateService.ipLocationGateway.UpdateByPK(location); }
public static void AddLocation(IpLocation location) { IPLocateService.ipLocationGateway.AddNew(location); }
public void UpdateByPK(IpLocation objIpLocation) { objIpLocation.UpdateTime = DateTime.Now; objIpLocation.UpdateStamp = Guid.NewGuid().ToString(); this.dbGateway.UpdateByFieldValue("LocationID", objIpLocation.LocationID, objIpLocation); }
private async Task <string> GetLocation(string ip) { var location = await IpLocation.QueryGeographicalLocationAsync(ip); return(location.City + "," + location.CountryCode); }